answersLogoWhite

0


Best Answer

A NullPointerException is thrown when you attempt to access an object reference which is null.

Example:

String str = null;

str.equals("x"); // <- NullPointerException

To fix it, you must read the error message and find out what object is null. Determining how to ensure that this object is not set to null in the future must be made on a case-by-case basis.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Null pointer error occurs when you try to use a vacant array in the rest of your program. for example, to initialize another variable or using in an expression. So, the only & the best way to get rid of it is to rectify your program in a way so that it initializes the array element before it gets used further.

Actually, there are logical errors in your program.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How overcome problem of NullPointerException?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is NullPointerException?

A NullPointerException is an exception thrown by the Java Virtual Machine when you try to access a variable as if it were an object when it is contains null. For example, the following code would throw a NullPointerException: String s; if (s.charAt(0) == 'c') // this line throws NullPointerException return "s[0] is 'c'";


Can NullPointerException be used with ArithmaticException using throws keyword in java?

No. You cannot throw or catch Null pointer exceptions


What are the errors in this code?

the code is: function pppf($var1) { // Get PPPF Code Infomation $sql = "SELECT * FROM pppf_code"; $pppf_query = mysql_query($sql); while($pppf = mysql_fetch_assoc($pppf_query)) { $y = mysql_num_rows($pppf_query); if ($x&lt;=$y) { $pppf_i = $pppf['input_text']; $pppf_o = $pppf['output_text']; $pppf_input = array($pppf_input.", '$pppf_i'"); $pppf_output = array($pppf_output.", '$pppf_o'"); } } echo $pppf_input['0']." | ".$pppf_output['0']."&lt;br&gt;"; $pppf_out = str_replace($pppf_input, $pppf_output, $var1); echo $pppf_out; }


How does a rubber tree overcome the problem of overcrowding?

my answer is this: Some rubber tree seeds spits at the short distance and it repeats the whole cycle till it overcrowd.


Does exception always signal an error?

It depends on exactly how you define an error. If an exception is thrown, then it means something has gone wrong. Some Exceptions, such as a NullPointerException, will almost certainly signal an error in your code or data. Others, such as IOExceptions, can be caused by things outside your control, and would probably not be considered errors.

Related questions

How do you overcome problem of NullPointerException?

By making sure that we do a null check everytime before using reference variables.


How do you overcome a problem?

It depends on what it is.


What is NullPointerException?

A NullPointerException is an exception thrown by the Java Virtual Machine when you try to access a variable as if it were an object when it is contains null. For example, the following code would throw a NullPointerException: String s; if (s.charAt(0) == 'c') // this line throws NullPointerException return "s[0] is 'c'";


How you overcome the Indian problems?

There is no problem *****


What problem for Aristotle was the hardest to overcome?

i


What can leaners do to overcome this problem of drop out?

Leave it


What problem did Helen Keller have to overcome?

She was blind!


Overcome?

To succeed in dealing with (a problem or difficulty).


What is a problem Barack Obama had to overcome?

Racism


What can be done to overcome the shortage of electricity?

use less power can overcome the problem of powershortage making dms


What obstacles did Amelia Earhart have to overcome?

Amelia Earhart had to first overcome prejudice and the obvious problem of money


How you will be able to overcome form you mti problem?

auto