i have wrote code use custom dialog application , thought going until had force crashed. had looked @ logcat , says unable add window hoping can assist me solve problem.
logcat:
08-23 02:05:22.836: e/androidruntime(898): fatal exception: main 08-23 02:05:22.836: e/androidruntime(898): java.lang.nullpointerexception 08-23 02:05:22.836: e/androidruntime(898): @ com.theproblemsolver.mainactivity$1.run(mainactivity.java:42) 08-23 02:05:22.836: e/androidruntime(898): @ android.os.handler.handlecallback(handler.java:725) 08-23 02:05:22.836: e/androidruntime(898): @ android.os.handler.dispatchmessage(handler.java:92) 08-23 02:05:22.836: e/androidruntime(898): @ android.os.looper.loop(looper.java:137) 08-23 02:05:22.836: e/androidruntime(898): @ android.app.activitythread.main(activitythread.java:5041) 08-23 02:05:22.836: e/androidruntime(898): @ java.lang.reflect.method.invokenative(native method) 08-23 02:05:22.836: e/androidruntime(898): @ java.lang.reflect.method.invoke(method.java:511) 08-23 02:05:22.836: e/androidruntime(898): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 08-23 02:05:22.836: e/androidruntime(898): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 08-23 02:05:22.836: e/androidruntime(898): @ dalvik.system.nativestart.main(native method)
mainactivity:
public class mainactivity extends activity { textview tps; textview tps1; textview tps2; textview tps3; button tpsbutton1; button getanswer; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); view mainview = getlayoutinflater().inflate(r.layout.activity_main, null); setcontentview(mainview); final dialog dialog = new dialog(this); dialog.setcontentview(r.layout.customdialog); dialog.settitle("theproblemsolver"); mainview.post(new runnable() { public void run() { dialog.show(); tps = (textview) findviewbyid(r.id.tps); tps1 = (textview) findviewbyid(r.id.tps1); tps2 = (textview) findviewbyid(r.id.tps2); tps3 = (textview) findviewbyid(r.id.tps3); tpsbutton1 = (button) findviewbyid(r.id.tpsbutton1); tpsbutton1.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { dialog.dismiss(); } } ); } }); final edittext et = (edittext) findviewbyid(r.id.edittext1); button getanswer = (button) findviewbyid(r.id.button1); getanswer.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if (et.gettext().tostring().length()==0) { toast.maketext(getapplicationcontext(),"can't blank!",toast.length_long).show(); }else{ edittext et = (edittext) findviewbyid(r.id.edittext1); string searchterm = et.gettext().tostring().trim(); intent in = new intent(mainactivity.this, listview.class); in.putextra("tag_search", searchterm); startactivity(in); } }}); } @override protected void onstop() { // todo auto-generated method stub super.onstop(); } }
customdialog.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <textview android:id="@+id/tps" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.01" android:text="example" android:textappearance="?android:attr/textappearancelarge" /> <textview android:id="@+id/tps1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.02" android:text="example" android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/tps2" android:layout_width="match_parent" android:layout_height="53dp" android:text="example" android:textappearance="?android:attr/textappearancelarge" /> <textview android:id="@+id/tps3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.02" android:text="example" android:textappearance="?android:attr/textappearancemedium" /> <button android:id="@+id/tpsbutton1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="ok" /> </linearlayout>
just small mistake in findviewbyid().
tps = (textview) findviewbyid(r.id.tps); tps1 = (textview) dialog.findviewbyid(r.id.tps1); tps2 = (textview) dialog.findviewbyid(r.id.tps2); tps3 = (textview) dialog.findviewbyid(r.id.tps3); tpsbutton1 = (button) dialog.findviewbyid(r.id.tpsbutton1);