slider - Nullpointer exception for AndroidImageSlider DefaultSliderView In Android Studio, Build 22.0.1 -
this stack trace :
08-16 10:23:40.006 19022-19022/com.world.innov.ebilling e/androidruntime﹕ fatal exception: main process: com.world.innov.ebilling, pid: 19022 java.lang.runtimeexception: unable start activity componentinfo{com.world.innov.ebilling/com.world.innov.ebilling.mainactivity}: java.lang.nullpointerexception: attempt invoke virtual method 'void android.os.bundle.putstring(java.lang.string, java.lang.string)' on null object reference @ android.app.activitythread.performlaunchactivity(activitythread.java:2325) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2390) @ android.app.activitythread.access$800(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1303) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5257) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698) caused by: java.lang.nullpointerexception: attempt invoke virtual method 'void android.os.bundle.putstring(java.lang.string, java.lang.string)' on null object reference @ com.world.innov.ebilling.mainactivity.oncreate(mainactivity.java:52) @ android.app.activity.performcreate(activity.java:5990) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1106) @ android.app.activitythread.performlaunchactivity(activitythread.java:2278) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2390) at android.app.activitythread.access$800(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1303) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5257) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698)
this activity :
import java.util.hashmap; import com.daimajia.slider.library.sliderlayout; import com.daimajia.slider.library.slidertypes.basesliderview; import com.daimajia.slider.library.slidertypes.basesliderview.onsliderclicklistener; import com.daimajia.slider.library.slidertypes.defaultsliderview; import android.app.activity; import android.content.intent; import android.content.sharedpreferences; import android.content.sharedpreferences.editor; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.window; import android.widget.button; public class mainactivity extends activity implements onsliderclicklistener { public static final string my_prefs_name = "myprefsfile"; private sliderlayout mdemoslider; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.activity_main); mdemoslider = (sliderlayout) findviewbyid(r.id.slider); hashmap<string, integer> file_maps = new hashmap<string, integer>(); file_maps.put("a", r.drawable.invoicebyhand); file_maps.put("b", r.drawable.invoicebymobile); file_maps.put("c", r.drawable.analysis); (string name : file_maps.keyset()) { defaultsliderview defaultsliderview = new defaultsliderview(this); // initialize sliderlayout defaultsliderview .description(name) .image(file_maps.get(name)) .setscaletype(basesliderview.scaletype.fit) .setonsliderclicklistener(this); //add information defaultsliderview.getbundle() .putstring("extra", name); mdemoslider.addslider(defaultsliderview); } mdemoslider.setpresettransformer(sliderlayout.transformer.rotateup); mdemoslider.setpresetindicator(sliderlayout.presetindicators.center_bottom); mdemoslider.stopautocycle(); sharedpreferences prefs = getsharedpreferences(my_prefs_name, mode_private); string pin = prefs.getstring("pin", ""); if (pin.equals("")) { disableletsgo(); intent = new intent(this, tocactivity.class); startactivity(i); } else { disablesignup(); } } @override public void onsliderclick(basesliderview slider) { // todo auto-generated method stub } }
my question "can see why getting null pointer exception @ line 52 guess defaultsliderview"?
line 52 : defaultsliderview.getbundle() .putstring("extra", name);
i using android studio 22.0.1 buildtoolversion. did not face problem while doing project on eclipse. first time using android studio. migrated project success , getting run time exception. using androidimageslider daimajia.
update: defaultsliderview returning null bundle(thanks @hariram). how should proceed or there replace bundle ?
update2: removed line 52. working.
defaultsliderview.getbundle()
is returning null here trying put values in null bundle. because of app crashing.
defaultsliderview.getbundle() .putstring("extra", name);
removing line not making bad effect on app should remove it.
Comments
Post a Comment