• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why this program can't run

 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I don't get it why this code isn't running right, because the methodology seem to right. anyhow this what i get when i run it


 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

that this have some kind problem
 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


{ TokenN++;
System.out.println("Space "+ space+ " tokenizer "+TokenN+"token :"+str.nextToken());
}
TokenN=0;
}
}
catch (FileNotFoundException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
}
}
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace tells you that a NullPointerException occurs in the constructor of StringTokenizer. The API documentation for the constructor of StringTokenizer says:

public StringTokenizer(String str, String delim)

...

Throws: NullPointerException - if str is null

Most likely you are passing null to the constructor of StringTokenizer.
 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:The stack trace tells you that a NullPointerException occurs in the constructor of StringTokenizer. The API documentation for the constructor of StringTokenizer says:

public StringTokenizer(String str, String delim)

...

Throws: NullPointerException - if str is null

Most likely you are passing null to the constructor of StringTokenizer.


that what i did here:

String FileName="C:/Users/Desktop/file.csv";
try{
BufferedReader read = new BufferedReader (new FileReader(FileName));
StringTokenizer str= null;
int space=0, TokenN=0;
while ((FileName = read.readLine())!=null);

{
space++;
str = new StringTokenizer(FileName,",");
while (str.hasMoreTokens())
{.....

still get the error
 
Tony Docherty
Bartender
Posts: 2953
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You have a semi colon at the end of the line so this line repeats until FileName is null and then the rest of the code executes.
 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
You have a semi colon at the end of the line so this line repeats until FileName is null and then the rest of the code executes.

ok thank now is working
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And why are you using a tokenizer, which has been regarded as legacy code for over ten years?
 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:And why are you using a tokenizer, which has been regarded as legacy code for over ten years?
sorry for the later reply
because my prof ask me do it, i anyhow that was a option (either use split or tokoz)
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringTokenizer is still very old‑fashioned code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic