Results 1 to 2 of 2
- 06-07-2012, 03:05 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 1
- Rep Power
- 0
Trouble with reading csv into object array
Hi there,
I am trying to read a csv file into an array (of objects) and then display everything in the array.. I can't seem to find what the problem is.
here is my code:
I get these errors:Java Code:import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; public class Control { static Model[] m; public static void readFromText() throws IOException{ int counter=0; String line; BufferedReader br = new BufferedReader (new FileReader("studentcard.csv")); line = br.readLine(); int a = countRows(); Model[] m = new Model [100]; while (line!=null){ String temp[]; temp=line.split(","); m [counter]= new Model (temp[0], temp[1], Integer.parseInt(temp[2])); line=br.readLine(); counter ++; } } public static String listArray(){ String s=""; for(int i=0;i<3;i++){ s+=m[i].toString()+"\n"; } return s; } public static void main(String[] args) throws IOException { readFromText(); listArray(); } }
Exception in thread "main" java.lang.NullPointerException
at Control.listArray(Control.java:55)
at Control.main(Control.java:63)
Thanks
- 06-07-2012, 03:36 PM #2
Re: Trouble with reading csv into object array
There is a variable at line 55 with a null value that is being used to reference an object. Look at that line and find the variable with the null value and then backtrack in the code to see why it does not have a non-null value.Exception in thread "main" java.lang.NullPointerException
at Control.listArray(Control.java:55)If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
Java word scramble -Trouble reading input
By dru36 in forum New To JavaReplies: 15Last Post: 11-26-2011, 07:09 PM -
Having trouble opening and reading a txt file
By DBaskov in forum New To JavaReplies: 14Last Post: 01-29-2011, 02:55 AM -
Trouble with Try Catch blocks and file reading.
By theBurgh22 in forum New To JavaReplies: 2Last Post: 11-30-2010, 01:11 AM -
Having trouble reading external txt file to an array
By Metastar in forum New To JavaReplies: 18Last Post: 07-21-2010, 11:29 PM -
Trouble creating object that includes array
By Desdenova in forum New To JavaReplies: 7Last Post: 05-18-2010, 07:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks