*
The moose likes Beginning Java and the fly likes why this program can't run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why this program can Watch "why this program can New topic
Author

why this program can't run

Andres John
Ranch Hand

Joined: Jun 07, 2012
Posts: 34

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

Joined: Jun 07, 2012
Posts: 34

that this have some kind problem
Andres John
Ranch Hand

Joined: Jun 07, 2012
Posts: 34


{ 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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Andres John
Ranch Hand

Joined: Jun 07, 2012
Posts: 34
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

Joined: Aug 07, 2007
Posts: 2172
    
  47

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

Joined: Jun 07, 2012
Posts: 34
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

Joined: Oct 13, 2005
Posts: 37962
    
  22
And why are you using a tokenizer, which has been regarded as legacy code for over ten years?
Andres John
Ranch Hand

Joined: Jun 07, 2012
Posts: 34
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

Joined: Oct 13, 2005
Posts: 37962
    
  22
StringTokenizer is still very old‑fashioned code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why this program can't run
 
Similar Threads
NullPointerException when starting ANY Webstart-Application
Applet doesn't load
Displaying the Color on a frame based on the RGB values.
Can't get Max's app to run
Trusted and Signed Applet still gets java.io.filepermission read error