run time error... thread
hi, all, i got a strange problem on my program..i could compiler my program..but i can`t get it run properly...pls help
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;
publicclass Test{
private Scanner theKbd;
Test()
{
}
private String readString(String userInstruction)
{
String aString =null;
try
{
System.out.print(userInstruction);
aString = theKbd.nextLine();
}
catch (NoSuchElementException e)
{
//if no line was found
System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
}
catch (IllegalStateException e)
{
// if this scanner is closed
System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
}
return aString;
}
publicstaticvoid main(String[] args)
{
Scanner scan =new Scanner(System.in);
String userInput;
Test example1 =new Test();
System.out.println("Testing readString function Demo");
userInput = example1.readString("Please your String");
System.out.println("Your input is " + userInput);
}
//the result come up as following
// Testing readString function Demo
//
// Please your StringException in thread "main" java.lang.NullPointerException
//at Test.readString(Test.java:22)
//at Test.main(Test.java:46)
}

