• 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

why this program can't run

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

that this have some kind problem
 
Andres John
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
}
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
StringTokenizer is still very old‑fashioned code.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic