• 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

ArrayIndexOutOfBoundsException: 1 at readFile.main

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is due to when a line is read from the stream and subsequently split into an array. Your code does not check how many elements are in the array. You simply access each element after the split. You need to run your code in debug to find out why the array does not contain the number of elements you are expecting it to.
 
Yudhistra Verma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
debug:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at readFile.main(readFile.java:42)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Still same message ...Can't understand why is it so..
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.println is your best friend. print out the length of the array before you acess it. print out some of the elements. Make sure it really holds what you think it holds.
 
reply
    Bookmark Topic Watch Topic
  • New Topic