• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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!
 
straws are for suckers. tiny ads are for attractive people.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic