Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |
AtheistOfFail
Caldari
|
Posted - 2011.01.16 04:07:00 -
[1]
Edited by: AtheistOfFail on 16/01/2011 04:09:51 I keep getting a NoSuchElementException on data input from a file. It's a simple while loop that checks if there's upcoming elements and drags the next 2 (a license plate and an operation such as ARRIVE or DEPART). Error appears to happen during the operation loading phase, not the license part.
Input file is something along the lines of "XXXXX YYYYY" where X are the license plates and Y are the operations. When the while loop cycles it should check and grab the next 2. Anyone got any ideas why this is is failing miserably.
PS: This is not EvE related at all. But still, i figure someone here can go "You're doing it wrong fool" same as any other programming forum.
PSS: Unless i got it wrong, .next() should only grab the next string up to the white space and then continue from there.
|
Salmod
Havoc Inc
|
Posted - 2011.01.16 05:25:00 -
[2]
Post some sample code so we can get a better idea what you're trying to do (i.e. what object you're calling .next() on, etc).
|
AtheistOfFail
Caldari
|
Posted - 2011.01.16 05:56:00 -
[3]
Originally by: Salmod Post some sample code so we can get a better idea what you're trying to do (i.e. what object you're calling .next() on, etc).
Scanner file = new Scanner ("Garage.txt"); FileWriter out = new FileWriter ("Output.txt"); PrintWriter outfile = new PrintWriter (out);
outfile.println("Parking Garage v0.1 Sample Output");
while (file.hasNext()) { String license = file.next(); String operation = file.next(); // Crashes at this line. }
also, there is data to be processed. Data should be picked up word by word. There are 2 words in the lines.
|
Lutz Major
|
Posted - 2011.01.16 06:41:00 -
[4]
Edited by: Lutz Major on 16/01/2011 06:43:10 Your program is correct. you only have one entry! Because you scan the String "Garage.txt" and not the content of the file ;)
Edit: try new Scanner(new File("Garage.txt"));
|
Salmod
Havoc Inc
|
Posted - 2011.01.16 07:03:00 -
[5]
Yeah, what he said :) You might need to put the full path to the file, or use the class loader to get an InputStream to pass to the Scanner constructor (assumming the file is on the classpath).
PS. You could have tracked this down by logging out the value of license, which would have been "Garage.txt" rather than the contents of the file as you were expecting.
|
AtheistOfFail
Caldari
|
Posted - 2011.01.16 17:13:00 -
[6]
Originally by: Lutz Major Edited by: Lutz Major on 16/01/2011 06:43:10 Your program is correct. you only have one entry! Because you scan the String "Garage.txt" and not the content of the file ;)
Edit: try new Scanner(new File("Garage.txt"));
Epic fail! I'll be trying that today. I have a feeling it will work correctly.
|
Zeta Zhul
Caldari Preemptive Paranoia
|
Posted - 2011.01.17 17:02:00 -
[7]
Are you posting your homework assignments here?
|
PsyKzz
Minmatar Antares Shipyards Phalanx Alliance
|
Posted - 2011.01.18 23:20:00 -
[8]
Doesn't everyone? PsyK |
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |