java - Android throwing null pointer exception when accessing a keyboard from another fragment -
so have fragment activity uses fragments keyboard add marker map , kep getting null pointer exception. i'm accessing keyboard in host fragment add data list.to clear keyboard being used 2 fragments @ same time. code(this fragment access keyboard fragment):
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); final edittext textlat = (edittext)findviewbyid(r.id.textlat); final edittext textlong = (edittext)findviewbyid(r.id.textlong); edittext po = (edittext)findviewbyid(r.id.podata); setcontentview(r.layout.activity_maps); setupmapifneeded(); mmap.addmarker(new markeroptions().position(new latlng(0, 0)).title("marker")); mmap.setmylocationenabled(true); /*this line throws error*/po.setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view v, int keycode, keyevent event) { if (keycode == keyevent.keycode_enter && event.getaction() == keyevent.action_down) { int latitudei = integer.parseint(textlat.gettext().tostring()); int logitudei = integer.parseint(textlong.gettext().tostring()); mmap.addmarker(new markeroptions().position(new latlng(latitudei, logitudei))); } return false; } }); }
this keyboard's fragment
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (getarguments() != null) { final edittext po = (edittext)getactivity().findviewbyid(r.id.podata); edittext textlat = (edittext)getactivity().findviewbyid(r.id.textlat); edittext textlong = (edittext)getactivity().findviewbyid(r.id.textlong); listview data = (listview)getactivity().findviewbyid(r.id.listview); mparam1 = getarguments().getstring(arg_param1); mparam2 = getarguments().getstring(arg_param2); arrayadapter<string> arrayadapter = new arrayadapter<string>( getactivity(), android.r.layout.simple_list_item_1, poin); data.setadapter(arrayadapter); po.setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view v, int keycode, keyevent event) { if (keycode == keyevent.keycode_enter && event.getaction() == keyevent.action_down) { poin.add(po.gettext().tostring()); } return false; } }); } }
stack trace:
caused by: java.lang.nullpointerexception @ com.example.adrian.xxxxxxxxxx.mapsactivity.oncreate(mapsactivity.java:31) @ android.app.activity.performcreate(activity.java:5312) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1111) @ android.app.activitythread.performlaunchactivity(activitythread.java:2552) at android.app.activitythread.handlelaunchactivity(activitythread.java:2653) at android.app.activitythread.access$800(activitythread.java:156) at android.app.activitythread$h.handlemessage(activitythread.java:1355) at android.os.handler.dispatchmessage(handler.java:102) at android.os.looper.loop(looper.java:157) at android.app.activitythread.main(activitythread.java:5872) at java.lang.reflect.method.invokenative(native method) at java.lang.reflect.method.invoke(method.java:515) at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:852) at com.android.internal.os.zygoteinit.main(zygoteinit.java:668) at dalvik.system.nativestart.main(native method)
a null pointer exception on line of form a.b.c means on left-hand side of dot null. in example :
either null;
or a.b null.
there can no other reason. so, textview.gettext() never returns null, possibility user null.
Comments
Post a Comment