• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

123 Neutral

About Belgium

  • Rank
  1. Java: Cannot find symbol error

    Thanks, LorenzoGatti.  I didn't quite understand what you were referring to and am still too ignorant to know if you were telling me the answer but you did send me down a path of investigation which resulted in a fix.   Anyways, I have made the problem go away.  I believe the problem is related to the build order of the jar files.  When I put "common.jar" at the top of the compile list the problem goes away.   My ignorant theory:   common.jar is used in many other jar files.  Many of those other jar files are also included in the problem file, "detroit.jar".  When I make a change to common.jar it isn't being seen by detroit.jar because an earlier .jar file has already been compiled which includes the non-editted version of the classes in common.jar.  It's this old version of the classes in common.jar that are being seen by detroit.jar.  The class is there but the new method is not.  New classes and methods are seen but new methods of previously existing classes are not.    Odd thing is, after moving common.jar to the top of the compile list, compiling successfully, then moving common.jar to the bottom of the compile list, it still compiles fine so there's some understanding I still don't have here.  I can duplicate and resolve the problem at will at this point by adding new methods.   So, other than ensuring common.jar is always at the top of the compile list, is there a better way of avoiding this problem? 
  2. 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?
  3. Parsing String sometimes doesn't work.

    [quote name='serioso' timestamp='1332456186' post='4924456'] The null character is not considered whitespace in Java. You'll either have to adjust your regex to "[\0\\s]+", or clean up your input data files (if you have that option). [/quote] Thanks! I changed it to "[\\s\\x00]+" and that seems to work.
  4. [font=courier new,courier,monospace]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.[/font] [font=courier new,courier,monospace]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. [/font][font=courier new,courier,monospace]Let's see if changing the font helps.[/font] [font=courier new,courier,monospace]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? [/font]
  5. Program keeps crashing

    [font=courier new,courier,monospace]Are you sure it's crashing? Maybe the console window is closing after the program has finished? It doesn't crash for me when I run it from a command line. What happens if you add some code to have the user 'press any key' before exitting the program?[/font] [font=courier new,courier,monospace]Additionally, why is i += 5 in the following loop? Is the number I am requested to enter supposed to equal the number of enemies? When I enter '2' or '3' I am only ever asked to enter one enemy type.[/font] for(int i = 0; i < number; i += 5) { theBattleField.AddEnemy(); }
  6. One source file used in multiple projects?

    [quote name='way2lazy2care' timestamp='1327095799' post='4904688'] stick it in a jar. [/quote] Thanks. That does the trick.
  7. 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
  8. c++ Infinate loop help

    Once the do loop is entered the user is never again asked for an answer. So, since the do loop continues until the correct answer is given and the user is only once allowed to provide one... Also, I'm a little confused by this game. Why is randnumber initialized/used twice? It is initialized before the do loop then another randnumber is initialized upon entering the do loop. The randnumber within the do loop would seem to be creating a moving target for the user, if the user were allowed to guess. This seems somewhat different than the typical version of this game.
  9. 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. [code]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); } } [/code]
  10. [quote name='rip-off' timestamp='1305570387' post='4811559'] From playing around with your code, I couldn't reproduce your problem but one thing I found is that you should execute something like "CMD /C <batch file name>". Otherwise the batch file spawns in a long running sub-process that doesn't close. [/quote] Crap! Thanks for running it and letting me know it works. It got me looking in another direction and finally discovered that the .bat file I was editing wasn't actually the batch file I was trying to read with the code. Same name, different folders. I've found that reading the correct file results in the expected behavior. Anyone know where I can get those four hours back?
  11. 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]
  12. check out my stupid stock game

    [font="Courier New"]For game play, I'm wondering if it would be better to randomize when and which companies gain or lose. With hard coded events and given enough plays, it wouldn't be too hard to memorize what happens to who and when. I'd also beef up the display a bit. It took me a few moments to figure out what the information being presented meant. I'd display the current cost of each stock, how many stocks I currently own, and the current cash worth of those stocks. Now, I get A B C with some unknown value next to them, I have to go to the sell screen to figure out how many of each I own and then I have to do math. I thought the "any number other than 1 or 2 to go to next day" to be a bit clunky. I'd specify, press 'N' to go to the next day. It appears the stock price for every company is the same. I only played 10 turns, so maybe that changes. It seems like nTurns is tied to the number of times I visit the market. Knowing that the market will crash on visit 5 I can just visit the market, buy 0 stocks until it crashes, then buy stock at a greatly reduced price. [/font][font="Courier New"]I don't feel qualified to give you serious programming tips. However, I don't think you need to use global variables for this program. You also appear to have a lot of code which differs only slightly from other bits of code. You could probably reduce this with a function that handles these common task. I see you didn't use any structs or classes so I'm guessing you haven't gotten that far. [/font][font="Courier New"] I don't think the following does what you think it does. I suspect it may be the cause for the stock prices all being the same. [/font] if (nRandom == 1 || 2 || 3 || 4 || 5 || 6) [font="Courier New"]I'll leave the more in depth analysis for people who know what they are talking about. [/font]
  13. [quote name='Antheus' timestamp='1296665118' post='4768572'] Use ArrayList instead. Vector is effectively deprecated.[/quote] Thanks! [quote]The documentation says: "Searches for the first occurence of the given argument, testing for equality using the equals method. ". Did you override the 'equals' method of all items in your collection? This would be the same as overloading operator==.[/quote] I tried but the method was never called. I suspect there's more involved than making an equals() method. [quote]That is fairly unusual, how can Cat and House be related?[/quote] I'm sure I'm misusing == in this case. It's become a habit after running into find_if and being defeated. I could never get my head wrapped around predicates. Some examples I've seen for find_if include bind2nd which is yet another item I couldn't grok. In the case above, I'm using == to identify an object which contains what I'm looking for. House is a collection of items. However, each House has a unique object in them called Cat. If I have a group of Cats that I need to put somewhere, I look for a House which has that Cat. To get away from the Foo Bar stuff, here's some actual code; [code]private void parseAlarmLog(String fileName) { Vector vMdmAlarms = readAlarmLog(fileName); for (int i = 0; i != vMdmAlarms.size(); ++i) { MdmAlarm alarm = (MdmAlarm)vMdmAlarms.get(i); for (int k = 0; k != m_vSpans.size(); ++k) { MdmSpan span = (MdmSpan)m_vSpans.get(k); if (span.isForCircuit(alarm.getCircuit())) { span.add(alarm); } else { m_vSpans.add( new MdmSpan(alarm)); } } } } [/code] I'm trying to avoid the inner loop. Additionally, this is a process I seem to run into a lot. A vector of stuff needs to be parsed into another vector. Above, there may be hundreds of alarms but they report the same dozen of so spans. If there's a better way of handling that in C++ or java I'd love to know. In C++ I made a template that does it but it requires the objects to have specific methods. EDIT: I'm too stoopid to figure out how to properly format the code in the post tool.
  14. Hi, I'm trying to search a Java Vector for a match of specific parameters. I've tried .indexOf() but this appears to check whether the searched for object refers to the same object as one of the vector elements. This isn't what I want. In C++ in would usually use find() in the algorithms library and overload operator== in the object being searched. std::vector<House>::iterator it = find(vHouse.begin(), vHouse.end(), cat); bool House::operator== (const Cat& cat) const; Above, I'm searching for a Cat object within the vector of House objects. Other than iterating through each element in the vector, how do I do this in Java? Thanks.
  15. Below is a mock up of what I'm trying to make better. I have a object (House) which takes a number of other objects (Cat) in it's constructor. The number of objects it takes is unknown but there is a maximum number. The order the Cats are placed in the constructor is important as they will be acted on in that order. Currently, I'm default filling them. I had thought of using a vector in the House parameter list but there are several hundred possibilities and I'm not sure I'd want to generate a vector for each of them. Creating a function which generates a vector based on Cat objects seems to run into the same problem as the House Constructor. Ultimately, what happens is a vector of Houses is constructed. However, only one of them is selected for use later. Once selected the Cat objects it holds are acted upon. Is there a better way? Thanks. [code]class House { public: House(const Cat& a = Cat(), const Cat& b = Cat(), const Cat& c = Cat(), const Cat& d = Cat(), const Cat& e = Cat(), const Cat& f = Cat()) { if (a.isValid() == true) m_vCats.push_back(a); if (b.isValid() == true) m_vCats.push_back(; if (c.isValid() == true) m_vCats.push_back(c); if (d.isValid() == true) m_vCats.push_back(d); if (e.isValid() == true) m_vCats.push_back(e); if (f.isValid() == true) m_vCats.push_back(f); } private: std::vector m_vCats; }; int main() { Cat felix( Cat("felix") ); Cat morris( Cat("morris") ); Cat slyvester( Cat("sylvester") ); Cat fluffy( Cat("fluffy") ); Cat garfield( Cat("garfield") ); Cat heathcliff( Cat("heathcliff") ); Cat eric( Cat("eric the cat") ); std::vector vHouses; vHouses.push_back( House(felix) ); vHouses.push_back( House(felix, garfield) ); vHouses.push_back( House(felix, heathcliff) ); vHouses.push_back( House(morris, slyvester) ); vHouses.push_back( House(eric, morris, garfield, slyvester) ); vHouses.push_back( House(felix, morris, eric, fluffy, garfield) ); vHouses.push_back( House(morris, felix, eric, fluffy, garfield) ); // Blah blah blah // Do some stuff with one of the elements of vHouses. }[/code]
  • Advertisement