Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading a file and getting run time error

 
Jithesh Kumar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i am reading a file and converting the string to integer it is giving me
java.lang.NumberFormatException:For input string:"" run time error

this is the code

BufferedReader leagueReader=new BufferedReader(new

FileReader(leagueFile));
String record;
while((record=leagueReader.readLine())!=null){
String del="|";
String[] fields=record.split(del);
int objectID=Integer.parseInt(fields[0]);---this line is giving the error.
int year=Integer.parseInt(fields[1]);
String season=fields[2];
String title=fields[3];
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bon jith wrote:when i am reading a file and converting the string to integer it is giving me
java.lang.NumberFormatException:For input string:"" run time error

this is the code



Try outputing record and/or fields[0] on each loop in after the split() command. You will then probably see a missing piece of data. You will have to do a check on fields[0] to make sure it is not a blank string.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic