Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What does this mean ?java.lang.NullPointerException

Posted on 2003-11-26
13
Medium Priority
?
2,571 Views
Last Modified: 2012-08-13
What does this mean ?
Uncaught exception in evaluation: java.lang.NullPointerException.

How would you fix this ?
0
Comment
Question by:pheats
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9823812
Tricky! You'll have to look through the 'evaluation' method for objects that should have been initialised but weren't
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9823828
what are you doing?
0
 

Expert Comment

by:twans
ID: 9824018
heyas.. not too sure if your new to java soooo..

could you post come code?

also, to expand on CEHJ's suggestion: "look through the 'evaluation' method for objects that should have been initialised but weren't "

in newbie's terms this means the following:

Object whatever; => Uninitialised object
Object whatever = new Object(); => the 'new' operator calls the constructor of that class and thus initialises the object..

Now in regard to your 'evaluation' method.. it may look like:

public void evaluation( object Object) {..} .. the parameter, Object, that you pass this method MUST be initilalised.. a common error is to have the following..

if {}
else {
evaluation(Object)..
}

but since you have not initialised the object initially, there is a CHANCE that you might pass an object assigned as null. A quick fix is possibly to modify your initial instance variable from:
Object object;
to Object object = new Object();

the success of this will be dependent on your code.

hope this helps somewhat :)

twans
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9824384
NullPointerException is thrown by the JVM when you are invoking a method on a null object.  Make sure your object references refer to actual objects before you invoke methods on them.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9824392
Please don't repeat comments that have already been made
0
 
LVL 92

Expert Comment

by:objects
ID: 9827279
> Please don't repeat comments that have already been made

I was about to make the same comment as I didn't see where anyone had explained that.
There are many ways an NPE can occur than  just an unitialised var, and is not a clear explanation of an NPE.
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9828371
>>Uncaught exception in evaluation

Does this not mean that no exception occured still but we need to use a try catch to catch the Exception ...
Correct me if I am wrong

eg for pheats
if you have

public int Test() throws NullPointerException
{
 if ( a< 5 )
     throw new NullPointerExeption
else
return a;
}

and we use

int b = Test()

this needs to be used as
try{
int b = Test()
}
catch (NullPointerException e)
{
 System.out.println(e);
}

Hope this helps.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9828496
No, NullPointerException does not have to be caught
0
 
LVL 92

Expert Comment

by:objects
ID: 9828520
> Does this not mean that no exception occured still but we need to use a try catch to catch the Exception ...

No it means an exception was thrown but it wasn't caught.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 120 total points
ID: 9828562
One way of reproducing this would be to call evaluation here:

public static void evaluation() {
      try {
            x();
      }
      catch(Exception e) {
            System.err.println("Uncaught exception in evaluation: " + e.getClass().getName());
      }
}

public static void x() {
      String s = null;
      int i = s.length();
}




0
 
LVL 1

Expert Comment

by:FesterWim
ID: 9850448
Maybe the simplest example would be:

String testString = null;
testString.substring(2); // Will throw a NullPointerException

Since testString does not refer to any real object, a NullPointerException is thrown.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9860088
8-)
0
 

Author Comment

by:pheats
ID: 9860122
I tried this and it proved that what is was doing was wrong.

I was able to catch the evaluation error.
Cheers
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question