i trying code given google here , getting nullpointerexception because getactivity()
in mdialogfragment
returning null. can't understand why. can explain error?
error log
07-11 21:12:59.240: e/androidruntime(1968): fatal exception: main 07-11 21:12:59.240: e/androidruntime(1968): java.lang.nullpointerexception 07-11 21:12:59.240: e/androidruntime(1968): @ android.app.alertdialog.resolvedialogtheme(alertdialog.java:142) 07-11 21:12:59.240: e/androidruntime(1968): @ android.app.alertdialog$builder.<init>(alertdialog.java:359) 07-11 21:12:59.240: e/androidruntime(1968): @ com.vinit.android.market.licensing.mdialogfragment.oncreatedialog(mdialogfragment.java:18) 07-11 21:12:59.240: e/androidruntime(1968): @ com.vinit.android.market.licensing.mainactivity$1.onclick(mainactivity.java:90) 07-11 21:12:59.240: e/androidruntime(1968): @ android.view.view.performclick(view.java:3511) 07-11 21:12:59.240: e/androidruntime(1968): @ android.view.view$performclick.run(view.java:14105) 07-11 21:12:59.240: e/androidruntime(1968): @ android.os.handler.handlecallback(handler.java:605) 07-11 21:12:59.240: e/androidruntime(1968): @ android.os.handler.dispatchmessage(handler.java:92) 07-11 21:12:59.240: e/androidruntime(1968): @ android.os.looper.loop(looper.java:137) 07-11 21:12:59.240: e/androidruntime(1968): @ android.app.activitythread.main(activitythread.java:4424) 07-11 21:12:59.240: e/androidruntime(1968): @ java.lang.reflect.method.invokenative(native method) 07-11 21:12:59.240: e/androidruntime(1968): @ java.lang.reflect.method.invoke(method.java:511) 07-11 21:12:59.240: e/androidruntime(1968): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 07-11 21:12:59.240: e/androidruntime(1968): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 07-11 21:12:59.240: e/androidruntime(1968): @ dalvik.system.nativestart.main(native method)
mainactivity.java
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); mstatustext = (textview) findviewbyid(r.id.status_text); mchecklicensebutton = (button) findviewbyid(r.id.check_license_button); mchecklicensebutton.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { (new mdialogfragment()).oncreatedialog(null).show(); //this line giving error } }); }
mdialogfragment.java
public class mdialogfragment extends dialogfragment{ @override public dialog oncreatedialog(bundle savedinstancestate) { // todo auto-generated method stub alertdialog.builder builder=new alertdialog.builder(getactivity()); //this line giving error builder.setmessage(r.string.testing).setpositivebutton(r.string.buy, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // todo auto-generated method stub } }).setnegativebutton(r.string.quit_button,new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // todo auto-generated method stub } }); return builder.create(); }}
change
(new mdialogfragment()).oncreatedialog(null).show(); //this line giving error
to
mdialogfragment dialog = new mdialogfragment(); dialog.show(getfragmentmanager(), "mdialogfragment");
Comments
Post a Comment