Exception in thread main java.lang.NullPointerException

The complete error is:

Exception in thread "main" java.lang.NullPointerException

at java.util.regex.Pattern.<init><Pattern.java:1129>

at java.util.regex.Pattern.compile<Pattern.java:822>

at java.util.Scanner$1.create<Scanner.java:391>

at java.util.Scanner$1.create<Scanner.java:389>

at sun.misc.LRUCache.forName<LRUCache.java:52>

at java.util.Scanner.useDelimiter<Scanner.java:1126>

at Ch2Monogram.main<Ch2Monogram.java:12>

I get the above error when I run the following program. It compiles fine.

/* Chapter 2 Sample Program: Displays the Monogram

File: Step1/Ch2Monogram.java

*/

import java.util.*;

class Ch2Monogram {

public static void main (String[] args) {

String name;

Scanner scanner = new Scanner(System.in);

scanner.useDelimiter(System.getProperty("line.seperator"));

name = scanner.next();

System.out.println("Name Entered: " + name);

}

}

What is the problem?

[1063 byte] By [jimendera] at [2007-11-27 8:46:34]
# 1
I haven't really used Scanner enough to provide a definitive answer, but I'd assume that you have to wait for the user to input something before assigning name to scanner.next().
Djaunla at 2007-7-12 20:49:19 > top of Java-index,Java Essentials,Java Programming...
# 2
System.getProperty("line.seperator") = nullYou wantSystem.getProperty("line.separator")
Norweeda at 2007-7-12 20:49:19 > top of Java-index,Java Essentials,Java Programming...
# 3
> System.getProperty("line.seperator") = nullOops. *Note to self*: read the entire stack trace
Djaunla at 2007-7-12 20:49:19 > top of Java-index,Java Essentials,Java Programming...
# 4
Doesnt scanner class have HASNExT method?You cannot just ask for it to retrieve you the next int or double without having it on the underlying stream.Put it into a WHile(sc.hasNext())I think that will work
charllescubaa at 2007-7-12 20:49:19 > top of Java-index,Java Essentials,Java Programming...
# 5
There is alist o hasNextXXX... try the most suitable for you
charllescubaa at 2007-7-12 20:49:19 > top of Java-index,Java Essentials,Java Programming...
# 6
> System.getProperty("line.seperator") = null> > You want> > System.getProperty("line.separator")Thanks, this worked !! It is amazing how many times that you can look ata piece of code and not see the error.
jimendera at 2007-7-12 20:49:19 > top of Java-index,Java Essentials,Java Programming...