Results 1 to 7 of 7
- 03-19-2009, 06:05 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 7
- Rep Power
- 0
Java Error: NoSuchElementException
I'm new to java and trying to finish this program. Each time I run it I get a NoSuchElementException. I've included the portion of the code where the error seems to be happening. If anyone knows how to solve this problem that would be great.
Not sure if this helps, but the information that is in the plain.dat file is below:Java Code:import java.util.Scanner; import java.io.*; public class TackitMJL { public static void main(String[] args) throws IOException { PlainMJL plain; RobotMJL r1, r2, r3, r4; plain = new PlainMJL(); r1 = new RobotMJL(); r2 = new RobotMJL(); r3 = new RobotMJL(); r4 = new RobotMJL(); r1.setRobotStatus(); r2.setRobotStatus(); r3.setRobotStatus(); r4.setRobotStatus(); int flag = 0; String whole_Line; //Plain Size int plain_Size; //Bomb Locations int bomb1_Location_X; int bomb1_Location_Y; int bomb2_Location_X; int bomb2_Location_Y; int bomb3_Location_X; int bomb3_Location_Y; int bomb4_Location_X; int bomb4_Location_Y; //Tackit Location int tackit_Location_X; int tackit_Location_Y; Scanner fileScan, Scan; fileScan = new Scanner (new File("Plain.dat")); whole_Line = fileScan.nextLine(); Scan = new Scanner (whole_Line); plain_Size = Scan.nextInt(); whole_Line = fileScan.nextLine(); Scan.useDelimiter(","); bomb1_Location_X = Scan.nextInt(); <------ Console says error is here. bomb1_Location_Y = Scan.nextInt(); whole_Line = fileScan.nextLine(); Scan.useDelimiter(","); bomb2_Location_X = Scan.nextInt(); bomb2_Location_Y = Scan.nextInt();
Java Code:100 5, 10 15, 25 6, 99 17, 3 12, 12
Last edited by xpngamer; 03-19-2009 at 06:26 AM.
- 03-19-2009, 06:46 AM #2
you forgot to set new Scan.
Java Code:whole_Line = fileScan.nextLine(); [B]Scan = new Scanner (whole_Line);[/B] Scan.useDelimiter[B](", "); // "comma and space" [/B] bomb1_Location_X = Scan.nextInt(); //<------ Console says error is here. bomb1_Location_Y = Scan.nextInt();USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 03-19-2009, 06:57 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 7
- Rep Power
- 0
That solved the first error but another popped up for this portion of the code right below it.
Java Code:whole_Line = fileScan.nextLine(); Scan = new Scanner (whole_Line); Scan.useDelimiter(", "); bomb3_Location_X = Scan.nextInt(); bomb3_Location_Y = Scan.nextInt(); whole_Line = fileScan.nextLine(); Scan = new Scanner (whole_Line); Scan.useDelimiter(", "); bomb4_Location_X = Scan.nextInt(); bomb4_Location_Y = Scan.nextInt(); whole_Line = fileScan.nextLine(); Scan = new Scanner (whole_Line); Scan.useDelimiter(", "); tackit_Location_X = Scan.nextInt(); tackit_Location_Y = Scan.nextInt(); <----- InputMismatchException Here
- 03-19-2009, 04:12 PM #4
try printing out the value of whole_Line and Scan before the error occured.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 03-19-2009, 04:38 PM #5
Member
- Join Date
- Mar 2009
- Posts
- 7
- Rep Power
- 0
When I print out what its scanning for whole_Line the output is "12, 12" which is what it should be, then after I use the delimiter and get rid of the "," what it scans next is "12" which again is what it should do, but when it goes to scan the next 12 it gives an Input Mismatch Exception.
- 03-19-2009, 04:54 PM #6
did you forget the space in useDelimiter?
useDelimiter(", "); // comma and space.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 03-19-2009, 07:37 PM #7
Member
- Join Date
- Mar 2009
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
[SOLVED] why am i getting this exception" java.util.NoSuchElementException
By ariz in forum New To JavaReplies: 5Last Post: 02-27-2009, 05:19 AM -
xception in thread "main" java.util.NoSuchElementException: No line found
By Tenn in forum New To JavaReplies: 12Last Post: 12-05-2008, 05:37 AM -
Exception in thread "main" java.util.NoSuchElementException
By vileoxidation in forum New To JavaReplies: 5Last Post: 09-17-2008, 07:29 AM -
Exception in thread "main" java.util.NoSuchElementException
By ragav in forum New To JavaReplies: 4Last Post: 06-08-2008, 02:19 PM -
[SOLVED] Exception in thread "main" java.util.NoSuchElementException
By thevoice in forum New To JavaReplies: 5Last Post: 05-14-2008, 01:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks