Android: NullPointerException in onTextChanged() method with EditText -
hello android developer,
i keep getting nullpointerexception in ontextchanged() method when edittext changes text. but not on smartphones. lg g2 not throw errors, eg samsung galaxy s 4 does. have 2 edittexts. entering numbers program takes both values , calculates something. , strange when keyboard opens , press key , del-key works.
here code:
edittext bestellt = new edittext(this); bestellt.setinputtype(inputtype.type_class_number); bestellt.setgravity(gravity.center_horizontal); bestellt.setems(3); bestellt.settextappearance(this, android.r.style.textappearance_medium); bestellt.setbackgroundcolor(color.parsecolor("#dbf2fc")); bestellt.sethint(html.fromhtml("<small><small><small>" + "bestellt" + "</small></small></small>")); //bestellt.setoverscrollmode(view.over_scroll_never); bestellt.setimeoptions(editorinfo.ime_flag_no_extract_ui|editorinfo.ime_flag_navigate_next); temptablerow.addview(bestellt); bestellt.setid(integer.parseint(integer.tostring(runde) + "90" + integer.tostring(i + 1) + "90" + integer.tostring(viewteilid))); //wievielereihen1 = tabellenlayout.getchildcount() - 1; //scrollviewhor.setsmoothscrollingenabled(false); bestellt.setonkeylistener(new view.onkeylistener() { public boolean onkey(view v, int keycode, keyevent event) { viewedittext1 = v; /*if ((event.getaction() == keyevent.action_down) && (keycode == keyevent.keycode_enter)) { //toast.maketext(getbasecontext(), "done gedrueckt", toast.length_short).show(); return true; }*/ return false; } }); bestellt.addtextchangedlistener(new textwatcher() { @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { //toast.maketext(getbasecontext(), integer.tostring(v.getid()), toast.length_long).show(); //int wievielereihen = tabellenlayout.getchildcount() - 1; try{ int id1, id2, id3, temppz; id1 = viewedittext1.getid(); string[] parts = integer.tostring(id1).split("90"); parts[2] = integer.tostring(integer.parseint(parts[2]) + 2); id3 = integer.parseint(parts[0] + "90" + parts[1] + "90" + parts[2]); parts[2] = integer.tostring(integer.parseint(parts[2]) - 1); id2 = integer.parseint(parts[0] + "90" + parts[1] + "90" + parts[2]); //kontrolle.settext("id1: " + id1 + " id2: " + id2 + " id3: " + id3); //viewedittext1.requestfocus(); /*inside here should not mistake try {//es müssen unbedingt werte eingegeben worden sein if (false) { //((edittext) findviewbyid(id1)).gettext().tostring().equals("") || ((edittext) findviewbyid(id1)).gettext().tostring().trim().length() == 0 || (((edittext) findviewbyid(id2)).gettext().tostring().equals("")) || ((edittext) findviewbyid(id2)).gettext().tostring().trim().length() == 0 //toast.maketext(getbasecontext(), "werte eingeben und bestaetigen!", toast.length_short).show(); } else temppz = 0; //keine ahnung warum //((edittext) findviewbyid(id1)).; temppz = berechnepunktzahl(integer.parseint(((edittext) findviewbyid(id1)).gettext().tostring()), integer.parseint(((edittext) findviewbyid(id2)).gettext().tostring())); ((textview) findviewbyid(id3)).settext(integer.tostring(temppz)); int c; int summe = 0; int tempoid = 0; (c = 0; c < runde; c++) { tempoid = integer.parseint((c + 1) + "90" + parts[1] + "90" + "3"); summe = summe + integer.parseint(((textview) findviewbyid(tempoid)).gettext().tostring()); } ((textview) findviewbyid(integer.parseint("222" + parts[1]))).settext(integer.tostring(summe)); //punktzahlen.add(integer.parseint(parts[0])-1,temppz); //integer sum = 0; //for ( integer : punktzahlen ) { // sum += i; //} //((textview) findviewbyid(integer.parseint("222"+parts[1]))).settext(integer.tostring(sum)); } catch (exception e) { //toast.maketext(getbasecontext(), "werte eingeben!", toast.length_long).show(); } */ inside here should not mistake } catch(exception e){ //this throws nullpointerexception toast.maketext(getbasecontext(), e.tostring(), toast.length_long).show(); } } @override public void aftertextchanged(editable s) { } });
this error stacktrace:
07-17 12:41:05.250 32282-32282/com.martins.martin.bestellen e/your_app_log_tag﹕ got error java.lang.nullpointerexception @ com.martins.martin.bestellen.secondactivity$2.ontextchanged(secondactivity.java:278) @ android.widget.textview.sendontextchanged(textview.java:8910) @ android.widget.textview.settext(textview.java:4866) @ android.widget.textview.settext(textview.java:4716) @ android.widget.edittext.settext(edittext.java:109) @ android.widget.textview.settext(textview.java:4691) @ android.widget.textview.onrestoreinstancestate(textview.java:4583) @ android.view.view.dispatchrestoreinstancestate(view.java:13722) @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2849) @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2849) @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2849) @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2849) @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2849) @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2849) @ android.view.viewgroup.dispatchrestoreinstancestate(viewgroup.java:2849) @ android.view.view.restorehierarchystate(view.java:13700) @ com.android.internal.policy.impl.phonewindow.restorehierarchystate(phonewindow.java:1952) @ android.app.activity.onrestoreinstancestate(activity.java:983) @ android.app.activity.performrestoreinstancestate(activity.java:955) @ android.app.instrumentation.callactivityonrestoreinstancestate(instrumentation.java:1144) @ android.app.activitythread.performlaunchactivity(activitythread.java:2306) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2386) @ android.app.activitythread.handlerelaunchactivity(activitythread.java:3947) @ android.app.activitythread.access$1000(activitythread.java:169) @ android.app.activitythread$h.handlemessage(activitythread.java:1283) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5476) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1283) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1099) @ dalvik.system.nativestart.main(native method)
i hope find problem. should have keyboard (any buffer????)
thanks lot, martin
now solved simulting del-keypress programmatically. bad solution not find problem...
Comments
Post a Comment