Results 1 to 4 of 4
Thread: RunTime Error
- 07-12-2010, 12:40 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
RunTime Error
Please help. This is my last project and I'll be done with summer school.
Here's the error that shows up when I run it:
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenize r.java:332)
at SoldCarTest.main(SoldCarTest.java:31)
----jGRASP wedge: exit code for process is 1.
I made 3 classes and a driver. Here they are:
1st class
2nd classJava Code:public class Date { private int day, year; private String month; public Date() { day = 0; year = 0; month = ""; } public Date(String m, int d, int y) { day = d; year = y; month = m; } public int dayIs() { return day; } public String monthIs() { return month; } public int yearIs() { return year; } public boolean equals(Date object) { return day==object.day&&year==object.year&& month.equalsIgnoreCase(object.month); } public String toString() { return month+", "+day+", "+year; } }
Java Code:public class Car { protected double dealerCost; protected int idNum, modelYear; protected Date dateA; protected String makeModel; public Car() { dealerCost = 0; idNum = 0; dateA = new Date(); modelYear = 0; makeModel = ""; } public Car(double d, int i, Date da, int mY, String makeM) { dealerCost = d; idNum = i; dateA = da; modelYear = mY; makeModel = makeM; } public double getDealerCost() { return dealerCost;} public int getIDNumber() { return idNum;} public Date getDateArrived() { return dateA;} public int getModelYear() { return modelYear;} public String getMakeModel() { return makeModel;} public boolean equals(Car other) { return Math.abs(dealerCost-other.dealerCost)<.0001&& idNum == other.idNum&&dateA.equals(other.dateA)&& modelYear==other.modelYear&&makeModel.equalsIgnoreCase( other.makeModel); } public String toString() { return "Dealer Cost:\t"+dealerCost+"\nId Number:\t"+ idNum+"\nDate Arrived:\t"+dateA+"\nMake:\t"+ makeModel+"\nModel:\t"+modelYear; } }
3rd class
driverJava Code:public class SoldCar extends Car { private double price; private String customer; private Date dateS; private int i; public SoldCar(double a, int b, Date v, int mY, String m, double p, String c, Date ds) { super(a, b, v, mY, m); price = p; customer = c; dateS = ds; } public SoldCar(int c, double a, String s, Date ds) { i = c; price = a; customer = s; dateS = ds; } public double getPrice() { return price;} public String getCustomer() { return customer;} public Date getDateSold() { return dateS;} public Double calcProfit() { return(price-dealerCost);} public String toString() { return super.toString()+"\nPrice:\t"+price+"\nCustomer:\t"+ customer+"\nProfit:\t"+calcProfit(); } public boolean equals(SoldCar object) { return super.equals(object)&&Math.abs(price-object.price)<.0001&& customer.equalsIgnoreCase(object.customer)&&dateS.equals( object.dateS); } }
Java Code:import java.io.*; import java.util.StringTokenizer; public class SoldCarTest { public static void main(String[] args) throws IOException { StringTokenizer t; Car[] Info = new Car[13]; int idNum, d, y, mY, q =0; String make, model, month, customer, l; Date B, S; double price, price2; FileReader fr = new FileReader("CarData.txt"); BufferedReader br = new BufferedReader(fr); String stringRead = br.readLine(); t = new StringTokenizer(stringRead, " "); l = t.nextToken(); while(l.charAt(0)!='X') { if(l.equalsIgnoreCase("c")) { price=Double.parseDouble(t.nextToken()); idNum = Integer.parseInt(t.nextToken()); month = t.nextToken(); d = Integer.parseInt(t.nextToken()); y = Integer.parseInt(t.nextToken()); mY = Integer.parseInt(t.nextToken()); model = t.nextToken(); B = new Date(month, d, y); Info[q] = new Car(price, idNum, B, mY, model); for(int i = 0; i < q; i++) { if(Info[q].getIDNumber()==idNum) { System.out.println("Same idNumber as another"+ " car in the array!"); Info[q] = null; q--; } if(Info[q].equals(Info[i])==true) { System.out.println("This car showed up more than once: "+ Info[i].getIDNumber()); } } } else if(l.equalsIgnoreCase("S1")) { idNum = Integer.parseInt(t.nextToken()); price=Double.parseDouble(t.nextToken()); customer=t.nextToken(); month = t.nextToken(); d = Integer.parseInt(t.nextToken()); y = Integer.parseInt(t.nextToken()); S=new Date(month, d, y); Info[q]=new SoldCar(idNum, price, customer, S); q++; } else { price=Double.parseDouble(t.nextToken()); idNum = Integer.parseInt(t.nextToken()); month = t.nextToken(); d = Integer.parseInt(t.nextToken()); y = Integer.parseInt(t.nextToken()); mY = Integer.parseInt(t.nextToken()); model = t.nextToken(); B = new Date(month, d, y); price2=Double.parseDouble(t.nextToken()); customer = t.nextToken(); month = t.nextToken(); d = Integer.parseInt(t.nextToken()); y = Integer.parseInt(t.nextToken()); S = new Date(month, d, y); Info[q]=new SoldCar(price, idNum, B, mY, model, price2, customer, S); for(int i = 0; i < q; i++) { if(Info[q].getIDNumber()==idNum) { System.out.println("Same idNumber as another"+ " car in the array!"); Info[q] = null; q--; } if(Info[q].equals(Info[i])==true) System.out.println("This car showed up more than once: "+ Info[i].getIDNumber()); } } } for(int i = 0; i < q; i++) { System.out.println("The remaining data in the array is: "+ Info[q]); } }}
- 07-12-2010, 12:46 PM #2
Obviously the file is empty, or not found or something like that.
Java Code:FileReader fr = new FileReader("CarData.txt"); BufferedReader br = new BufferedReader(fr); String stringRead = br.readLine(); System.out.println(stringRead); // <- what's happening here?? t = new StringTokenizer(stringRead, " ");Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 07-12-2010, 01:19 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
if I added that S.O.P line it just prints out the first line from my data. I forgot to give my data file:
All of that is my data file, including the 'X'Java Code:C 5000.00 1234 January 1 2004 2000 Honda_Accord S1 1234 6000.00 Roth February 15 2004 S2 8000.00 2222 January 15 2004 1999 Ford_F150 9500.00 Jones January 25 2004 C 14000.00 3333 June 6 2003 1999 GMC_Suburban C 5000.00 1222 January 1 2004 2000 Honda_Civic C 10000.00 4444 July 10 2002 2001 Toyota_Tundra S2 12000.00 5555 February 6 2003 1965 Ford_Mustang 15000 Williams September 4 2003 S1 3333 15650 Brown December 25 2003 C 10500.00 4000 July 10 2002 2001 Toyota_Tundra S2 9500.00 6666 January 21 2004 1999 Ford_F150 9000.00 Smith January 31 2004 C 5000.00 1222 January 1 2004 2000 Honda_Civic S2 8000.00 2222 January 15 2004 1999 Ford_F150 9500.00 Jones January 25 2004 S2 9900.00 6667 January 21 2004 1999 Ford_F150 9007.00 Byrd January 31 2004 X
- 07-12-2010, 01:30 PM #4
You never read more than one line of the file. At the end of the while loop you should read the next line from the file and tokenize it.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
Java Runtime Error! :(
By RoadRunner in forum New To JavaReplies: 6Last Post: 01-20-2011, 04:58 AM -
runtime error problems. please help!
By RoadRunner in forum Forum LobbyReplies: 0Last Post: 04-21-2009, 05:03 PM -
I can't fix this runtime error in my program
By Sinnergy in forum New To JavaReplies: 5Last Post: 02-25-2009, 04:29 PM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM -
Weblogic 5.0 runtime error with EJB 1.0
By somesh in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 08-25-2008, 03:09 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks