• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayStoreException  RSS feed

 
muhsin sabeer
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got ArrayStoreException occured in line-9 when I run the following code:
<CODE>
1 public static void main(String[] args) throws IOException {
2 BufferedReader br = new BufferedReader(new FileReader("data.txt"));
3 List lines = new ArrayList();
4 for(String line = br.readLine();line != null;line = br.readLine()) {
5 // split by comma
6 String[] fields = line.split(",");
7 lines.add(fields);
8 }
9 String[][] strings = (String[][]) lines.toArray(new String[lines.size()][]);
10 System.out.println("Lines="+strings.length);
11 }
</CODE>
Can anyone help me why it throw exception?

Thanks
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RU sure? I just ran your code and it worked!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!