android - Textview setText from EditText in alert dialog -
what's wrong code? application has been stopped.
public void names (view v) { alertdialog.builder alert = new alertdialog.builder(this); layoutinflater inflater = getlayoutinflater(); alert.setview(inflater.inflate(r.layout.dialog_signin, null)); alert.settitle("set players names"); alert.setpositivebutton(r.string.ok, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { textview j=(textview)findviewbyid(r.id.textview2); textview k=(textview)findviewbyid(r.id.textview3); edittext l=(edittext)findviewbyid(r.id.player1); edittext m=(edittext)findviewbyid(r.id.player2); string name1 = l.gettext().tostring(); string name2 = m.gettext().tostring(); j.settext(name1); k.settext(name2); } }); alertdialog dialog = alert.create(); dialog.show(); }
logcat:
06-08 18:07:20.613: d/libegl(20332): loaded /vendor/lib/egl/libegl_adreno.so 06-08 18:07:20.613: d/libegl(20332): loaded /vendor/lib/egl/libglesv1_cm_adreno.so 06-08 18:07:20.623: d/libegl(20332): loaded /vendor/lib/egl/libglesv2_adreno.so 06-08 18:07:20.623: i/adreno-egl(20332): : egl 1.4 qualcomm build: (cl4169980) 06-08 18:07:20.623: i/adreno-egl(20332): opengl es shader compiler version: 17.01.10.spl 06-08 18:07:20.623: i/adreno-egl(20332): build date: 12/01/13 sun 06-08 18:07:20.623: i/adreno-egl(20332): local branch: 06-08 18:07:20.623: i/adreno-egl(20332): remote branch: 06-08 18:07:20.623: i/adreno-egl(20332): local patches: 06-08 18:07:20.623: i/adreno-egl(20332): reconstruct branch: 06-08 18:07:20.673: d/openglrenderer(20332): enabling debug mode 0 06-08 18:07:26.448: d/androidruntime(20332): shutting down vm 06-08 18:07:26.458: w/dalvikvm(20332): threadid=1: thread exiting uncaught exception (group=0x415898b0) 06-08 18:07:26.458: e/androidruntime(20332): fatal exception: main 06-08 18:07:26.458: e/androidruntime(20332): java.lang.nullpointerexception 06-08 18:07:26.458: e/androidruntime(20332): @ com.example.game.mainactivity$1.onclick(mainactivity.java:87) 06-08 18:07:26.458: e/androidruntime(20332): @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:171) 06-08 18:07:26.458: e/androidruntime(20332): @ android.os.handler.dispatchmessage(handler.java:99) 06-08 18:07:26.458: e/androidruntime(20332): @ android.os.looper.loop(looper.java:213) 06-08 18:07:26.458: e/androidruntime(20332): @ android.app.activitythread.main(activitythread.java:5225) 06-08 18:07:26.458: e/androidruntime(20332): @ java.lang.reflect.method.invokenative(native method) 06-08 18:07:26.458: e/androidruntime(20332): @ java.lang.reflect.method.invoke(method.java:525) 06-08 18:07:26.458: e/androidruntime(20332): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:741) 06-08 18:07:26.458: e/androidruntime(20332): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:557) 06-08 18:07:26.458: e/androidruntime(20332): @ dalvik.system.nativestart.main(native method)
1. 06-08 18:15:27.578: d/androidruntime(20809): shutting down vm 06-08 18:15:27.578: w/dalvikvm(20809): threadid=1: thread exiting uncaught exception (group=0x415898b0) 06-08 18:15:27.578: e/androidruntime(20809): fatal exception: main 06-08 18:15:27.578: e/androidruntime(20809): java.lang.nullpointerexception 06-08 18:15:27.578: e/androidruntime(20809): @ com.example.game.mainactivity$1.onclick(mainactivity.java:92) 06-08 18:15:27.578: e/androidruntime(20809): @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:171) 06-08 18:15:27.578: e/androidruntime(20809): @ android.os.handler.dispatchmessage(handler.java:99) 06-08 18:15:27.578: e/androidruntime(20809): @ android.os.looper.loop(looper.java:213) 06-08 18:15:27.578: e/androidruntime(20809): @ android.app.activitythread.main(activitythread.java:5225) 06-08 18:15:27.578: e/androidruntime(20809): @ java.lang.reflect.method.invokenative(native method) 06-08 18:15:27.578: e/androidruntime(20809): @ java.lang.reflect.method.invoke(method.java:525) 06-08 18:15:27.578: e/androidruntime(20809): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:741) 06-08 18:15:27.578: e/androidruntime(20809): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:557) 06-08 18:15:27.578: e/androidruntime(20809): @ dalvik.system.nativestart.main(native method) 06-08 18:15:29.079: i/process(20809): sending signal. pid: 20809 sig: 9
you must getting npe
on getting values edittext
try following :
final view mylayout = inflater.inflate(r.layout.dialog_screen, null); alert.setview(mylayout); alert.settitle("set players names"); alert.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { textview j=(textview)mylayout.findviewbyid(r.id.textview2); textview k=(textview)mylayout.findviewbyid(r.id.textview3); edittext l=(edittext)mylayout.findviewbyid(r.id.player1); edittext m=(edittext)mylayout.findviewbyid(r.id.player2); string name1 = l.gettext().tostring(); string name2 = m.gettext().tostring(); j.settext(name1); k.settext(name2); log.i("j"+name1, "k"+name2); } });
Comments
Post a Comment