This week's giveaways are in the
MongoDB
and
Jobs Discussion
forums.
We're giving away four copies of
Mongo DB Applied Patterns
and 4 resume reviews from
Five Year Itch
and have the authors/reps on-line!
See
this thread
and
this one
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Mongo DB Applied Patterns
this week in the
MongoDB
forum
or a resume review from
Five Year Itch
in the
Jobs Discussion
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Error while trying to add an object to array list
Ajay Pratap
Greenhorn
Joined: Dec 09, 2008
Posts: 3
posted
Dec 09, 2008 03:11:00
0
Hi,
I am getting the following exception when I add an object to my array list:
Launcher$AppClassLoader(
ClassLoader
).loadClassInternal(
String
) line: not available
int flag = 0; int[] choice = new int[pizzaOrderList.size()]; int choice1 =0; int value=0; boolean repeatMenu=true; Scanner userInput = new Scanner(System.in); //read file order.txt try { //check if file exists if(new File("order.txt").exists()) { // variable to hold line from file String line; //variables to be used to create object String dateTime=""; int localUserId=0; String pizzaId=""; double totalCost=0.0; //object variable orderList objOrder= null; //create file object File file = new File ("order.txt"); //create a scanner Scanner scanner = new Scanner (file); //loop while there is a line to read while (scanner.hasNextLine ()) { //read line line=scanner.nextLine(); //split line into values dateTime=line.split(",")[0]; localUserId=Integer.parseInt(line.split(",")[1]); pizzaId=line.split(",")[2]; totalCost=Double.parseDouble(line.split(",")[3]); //create new object objOrder = new orderList(dateTime,localUserId,pizzaId,totalCost); //add to an Arraylist pizzaOrderList.add(objOrder); } System.out.println("PIZZAMAN - for your daily slice of life"); System.out.println(); int compare = userInfo.get(userId).getIdNumber(); int compare1=0; System.out.println("The following pizzas were ordered by you: "); for(int i=0;i<pizzaOrderList.size();i++) { compare1=pizzaOrderList.get(i).getLocalUserId(); //System.out.println(pizzaOrderList.get(i).getLocalUserId()); if(compare == compare1 ) { choice[value] = i; value++; flag=0; } else { flag=1; } } if(flag==0) { for(int i=0;i<value;i++) { System.out.println((i+1) + ". " + "Date and Time: " + pizzaOrderList.get(choice[i]).getDateTime() + " Pizza ID: " + pizzaOrderList.get(choice[i]).getPizzaId() + " Cost of Pizza: " + pizzaOrderList.get(choice[i]).getTotalCost()); System.out.println(); } while(repeatMenu) { System.out.println("If you wish to cancel a order press '1', if you wish to go back to the main menu please press '0' "); System.out.println("PLEASE NOTE : Only orders placed within last 20 minutes can be cancelled."); System.out.println("Please enter your choice: "); if(userInput.hasNextInt()) { choice1 = userInput.nextInt(); if(choice1 == 1) { repeatMenu = false; cancelOrder(userId,choice,value); } else if (choice1==0) { repeatMenu = false; mainMenu(userId); } else { repeatMenu=true; } } else { System.out.println("Invalid Choice"); repeatMenu=true; } } } else { System.out.println("You have not ordered a pizza yet!!"); mainMenu(userId); } } else { // File does not exist System.out.println("File does not exist"); } } catch(Exception e) { //display exception message System.out.println("Exception : "+ e.getMessage()); }
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8430
I like...
posted
Dec 09, 2008 03:26:00
0
Please don't start a new thread. Post in the existing one here
http://www.coderanch.com/t/417134/java/java/ClassNotFoundException
Closing this one
[
Donate a pint, save a life!
] [
How to ask questions
] [
Onff-turn it on!
]
I agree. Here's the link:
http://jrebel.com/download
subject: Error while trying to add an object to array list
Similar Threads
How to use canceled button in JOptionPane
Cannot find symbol error in switch-case
ClassNotFoundException
NullPointerException problem
writer's block on assignment, any help?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter