Question:
Null pointer exeption (simple java???)?
dudenell
2008-03-04 22:42:53 UTC
ok here is my program. its just supposed to display a name adn then output it...
public class testing {

static Library myLib;

public static void main(String[] args) {

//local variables
String PlayerName;

System.out.println("Please State your Player name");
PlayerName = Keyboard.readString();

myLib.clrscr();
System.out.println("this is your name" + PlayerName);


//End
}

}
here is my keyboard class
http://www.frag-gaming.com/download/Keyboard.class

and here is the error im getting
http://www.frag-gaming.com/download/myerror.jpg

any help?
Four answers:
Kaydell
2008-03-04 23:09:42 UTC
The variable, myLib is a class variable so it is automatically set to null.



In line 13, the Java program tries to dereference the variable, myLib which is null.



I think what the solution is that before line 13, you need to assign a Library object to the object reference variable, myLib.
Zurahn
2008-03-04 22:53:34 UTC
The .class file is the compiled file, so I can't evaluate the code in the keyboard class, but it clearly isn't reading from the keyboard properly. Also make sure that you're returning the String value in the readString() method.
Nargol
2008-03-04 23:02:48 UTC
Hi. I can decompile your class. But what's Library?

When I had removed the myLib.clrscr(), it works properly.
Nishanth Anil
2008-03-04 23:02:29 UTC
myLib.clrscr();



Remove this and just give it a try


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...