views:

331

answers:

1

Hello there, I'm creating an application that installs 3 Record Stores for the first run. Then on it has to work with the already installed values. The application works fine during the first run both in the emulator and in a mobile. But the second time run shows a null pointer exception after my splash screen loads. After the splash screen, I've got the loading of record stores. But the record stores also get deleted, updated during the first run cause of some features. During such times, the midlet runs without any problem. But when I open the application second time in my mobile, it springs up with an error message saying null pointer exception.

I need the following help... 1. Can I run the emulator again with the old recorstores? If so how? 2. How can I rectify the problem of null pointer exception?

Please help.

+3  A: 

To the point: just read the stacktrace and fix the null pointer accordingly.

The first line of the stacktrace should contain a line number of the source code where it is been caused. Open the source code and go to that line. It should look like:

someObject.doSomething();

Especially look there where the dot operator . is used to access or invoke some object instance. A NullPointerException on such a code line means that the someObject is actually null. It simply refers nothing. You can't access it nor invoke any methods on it.

All you need to do to fix a NullPointerException is to ensure that someObject is not null:

if (someObject == null) {
    someObject = new SomeObject();
}
someObject.doSomething();

Or alternatively only do the access/invocation if someObject is not null.

if (someObject != null) {
    someObject.doSomething();
}
BalusC
this should be pinned as suggestion to every question containing "NullPointerException"
Bozho