• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayStoreException

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RU sure? I just ran your code and it worked!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic