Jump to content

  • Log In with Google      Sign In   
  • Create Account


Belgium

Member Since 13 Jun 2007
Offline Last Active Feb 28 2013 03:56 PM
-----

Topics I've Started

Java: Cannot find symbol error

28 December 2012 - 11:13 AM

This has been driving me nuts for awhile.  I have an overloaded method which is located in a jar file.  This jar file has a number of common classes with are used by many other jar files.  The common jar file compiles without error.  I'll be calling it common.jar.

 

Whenever I try to use that method from detroit.jar I receive a "cannot find symbol" error.  Other usages of the method compile fine, just one specific version of the method gets the error message.

 

For example;
1. Foo.print(2, 3);
2. Foo.print(new File("x.txt"), 42);
3. Foo.print(false);
4. Foo.print("hi!");

 

Methods 1, 2 & 3 compile and work.  So my imports are there.  However, method 4 causes detroit.jar to fail compiling with the "cannot find symbol" error.  I know the method for #4 is there.  When I have Netbeans "goto source" it correctly finds the source method for #4.  When I "find usages" for #4 it correctly identifies the non-compiling usage of it so Netbeans knows it exists too.  The only difference between the first three working methods and the last method is the last method is new which seems to be key.

 

When I try to duplicate this problem from within a different jar, say chicago.jar, it compiles just fine.  So, there seems to be something specific between common.jar and detroit.jar which is conspiring to tick me off.  I've tried clean rebuild for both, no avail.  Renaming the #4 method gets the same error.  No changes I make in common.jar are being seen by detroit.jar.  However, those changes ARE seen by chicago.jar.  There are other jar files which detroit.jar imports and changes to those jar files compile/work just fine.  wtf.

 

Ideas?


Parsing String sometimes doesn't work.

22 March 2012 - 12:57 PM

Hello,

I am using the following to parse a String which has spaces as a delimiter.

List<String> elements = Arrays.asList(text.trim().split("\\s+"));

I've been using that line a lot for String parsing and have never had a problem until now.

It works as I desire for the String " DEVICE: CPM PROC UNIT: 3 PAIR: B ".
The result is "DEVICE:", "CPM", "PROC", etc.

It does not work for this String " DEVICE: SPAN UNIT: 2370 ".
The results are "DEVICE:", "", "SPAN". There's an empty string where I expect to see "SPAN".

This also does not work for this string, with similar results, " DEVICE: ALMCRD UNIT: 56"

I've also tried String temp[] = text.trim().split("[ ]+"). Same thing.

I'm lost. I don't know what I am missing here.


Edit: My original post ate a number of spaces in my examples between "DEVICE: " and the next element. There are more than 1 spaces between this texts. Let's see if changing the font helps.

Edit2: Loading the source file for the text in a hex editor, I see there is a 0x00 character in the place of one of the spaces. So, the three "spaces" between "DEVICE:" and "SPAN" is actually 0x20 0x00 0x20. That 0x00 character doesn't show up in the Strings that parse correctly. Isn't 0x00 considered whitespace and shouldn't "\\s+" include it?

One source file used in multiple projects?

20 January 2012 - 02:19 PM

Hi,

I've written a few classes in java which are useful in multiple projects. Unfortunately, without copy/pasting them I haven't been able to figure out how to use the classes in multiple projects.

In C++ I would just include the .h file and make sure the compiler knew where to look for it.

However, using Netbeans for my Java, I receive a "Package Folder Already Used in Project" message. How can I have just one source file but use it in multiple projects?

Thanks

Java Can't read non-CR lines from inputstream

08 July 2011 - 12:20 PM

Hello,

I'm using Ganymed to establish an SSH telnet session. I am able to read the information
coming from the telnet session as long as there is a carriage return.

I can send 'whoami' and read the response since it has a carriage return.

However, when I send 'passwd' the response does not contain a carriage return and I cannot read it.
I also can't read the ' it uses as a prompt for my input as it also doesn't have a carriage return.
What can I do to get all the bytes and not just those which end with a carriage return?

As a side issue, what's the point of .available()? It seems to always return 0 even though there
is stuff to be read. I've read "The available method for class InputStream always returns 0." so what's the point?

Below is what I am using to read the stream.

Thanks.

InputStream m_input = new StreamGobbler(m_session.getStdout());   
InputStream m_error = new StreamGobbler(m_session.getStderr());
String m_inputText = "";

byte[] buff = new byte[4096];

while(true)
{
     try
     {
    	if (m_input.available() > -1)
    	{
        	int len = in.read(buff);
        	if (len == -1)
        	{
            	break;
        	}
        	m_inputText += new String(buff, 0, len);
    	}
     }
     catch (Exception e)
     {
    	LogFile.print(e);
     }
}

Java. Unable to read more than one line from process

16 May 2011 - 11:25 AM

Hello,

I'm trying to read the results of a batch file. Currently, the batch files consists of the following lines;

ECHO Hi
ECHO There

However, my code is only reading the first line (Hi). It never reads "There". Playing around with my while loop it seems to me that readLine() never returns when it is called the second time.

What do I need to do to read more than just the first line of this batch file. Eventually this batch file will call another program which will output stuff other than a greeting.

Thanks.

[source lang="java"]try{ String line; Process p = Runtime.getRuntime().exec(batchFileName); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close();}catch (Exception err){ err.printStackTrace();}[/source]

PARTNERS