Click here to Skip to main content
16,014,662 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've got this code for reading information from a file and load it into a linked
list of nodes. but the code below crashes :-(

if (btn == btnLoad)
		{
             try
             {
             	booklist.clear();
                BufferedReader reader = new BufferedReader(new FileReader("BOOKDATA.txt"));
                String line= reader.readLine();
                Books ObjBook = new Books();
                while(line!=null)
                  {
                  	 String[] ObjectArray =line.split(" ");
                  	 Books BookObject=new Books(ObjectArray[0],ObjectArray[1],Double.parseDouble(ObjectArray[2]),Integer.parseInt(ObjectArray[3]),Integer.parseInt(ObjectArray[4]),ObjectArray[5],ObjectArray[6],ObjectArray[7]);
             	     booklist.add(BookObject);
             	     line = reader.readLine();
                  }
                reader.close();
             
             }
             catch(EOFException eof)
             {
             	System.out.println("End of file");
             }
             catch(FileNotFoundException fnf)
             {
             	System.out.println("File Not Found");
             }
             catch(IOException error)
             {
             	System.out.println("IO error");
             }
        }
Posted
Updated 19-Mar-12 4:13am
v2

1 solution

Please make sure to first convert those values from the Object array and afterwards to use them - with a validation:

Java
// short form

Book oBook = new Book(
 value == null ? alternateValue:originalValue,
 args2,
 args3

);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900