java - SharedPreferences in my adapter -


null pointer exception error.. i'm trying access sharedpreferences in adapter don't know why showing nullpointerexception. here log , code.

01-16 21:20:05.546  15405-15405/com.adequatsol.hdwallpaper e/androidruntime﹕ fatal exception: main process: com.adequatsol.hdwallpaper, pid: 15405 java.lang.runtimeexception: unable instantiate activity componentinfo{com.adequatsol.hdwallpaper/com.adequatsol.hdwallpaper.fullimageactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'android.content.sharedpreferences android.content.context.getsharedpreferences(java.lang.string, int)' on null object reference         @ android.app.activitythread.performlaunchactivity(activitythread.java:2546)         @ android.app.activitythread.handlelaunchactivity(activitythread.java:2758)         @ android.app.activitythread.access$900(activitythread.java:177)         @ android.app.activitythread$h.handlemessage(activitythread.java:1448)         @ android.os.handler.dispatchmessage(handler.java:102)         @ android.os.looper.loop(looper.java:145)         @ android.app.activitythread.main(activitythread.java:5942)         @ java.lang.reflect.method.invoke(native method)         @ java.lang.reflect.method.invoke(method.java:372)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1399)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1194)  caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.content.sharedpreferences android.content.context.getsharedpreferences(java.lang.string, int)' on null object reference         @ android.content.contextwrapper.getsharedpreferences(contextwrapper.java:184)         @ com.adequatsol.hdwallpaper.imageadapter.<init>(imageadapter.java:47)         @ com.adequatsol.hdwallpaper.fullimageactivity.<init>(fullimageactivity.java:28)         @ java.lang.reflect.constructor.newinstance(native method)         @ java.lang.class.newinstance(class.java:1650)         @ android.app.instrumentation.newactivity(instrumentation.java:1079)         @ android.app.activitythread.performlaunchactivity(activitythread.java:2536) 

here code snipet

sharedpreferences sharedpreferences ;   public integer [] selectedarray ; public imageadapter(context c){     mcontext = c;     sharedpreferences = mcontext.getsharedpreferences("mypref", 0);     int opt = sharedpreferences.getint("option", 0);     switch (opt)     {         case 1:             selectedarray = mthumbids ;             break;         case 2:             selectedarray = landthumbids ;             break;         case 3:             selectedarray = carsthumbids ;             break;     }  } 

pass activity context

gridview.setadapter(new imageadapter(youractivity.this)); 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -