I’ve two .java files: Read.java and Save.java. And I’m getting a NullPointerException when I try to launch my application. Logcat entries refer to both
Cursor cu = cr.query(URI, null, null, null, null); and
rc.Cont(destination.getAbsolutePath()); as the cause of NullPointerException.
But, I’ve already try Read.java apart and it’s working fine as I except to. I guess, it’s the call from another class which is doing trouble. Thanks for help.
—Read.java
public class ReadCon(String destination) {
`...`
public void Cont(String destination) {
ContentResolver cr = getContentResolver();
Cursor cu = cr.query(URI, null, null, null, null);
...
}
}
—Save.java
public class SaveEnd extends Activity {
File destination;
Fonctions f = new Fonctions();
//creerDossier return type is File
destination = f.creerDossier(2, Save.pathsList[i]);
ReadCon rc = new ReadCon();
rc.Cont(destination.getAbsolutePath());
}
This is the stack trace:
java.lang.NullPointerException
at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:91)
at projet.sarelo.ReadContacts.SaveContacts(Read.java:134)
at projet.sarelo.SaveEnd.onStart(Save.java:75)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1132)
at android.app.Activity.performStart(Activity.java:4320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1709)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Problem solved. Thanks all for help. Somehow, the
getContentResolver()called fromcont(String destination)was returningnullinSaveEndclass. I’ve used aContextinstance to set it right. This is my final code