Android app fails due to a java.lang.StackOverflowError -
i'm making android program , it's failing due stackoverflow error. have attached code. i'm using android studio. believe it's looping because of addtextchangedlistener can't understand why it's doing it.
my code:
rb1 = (radiobutton) findviewbyid(r.id.radiobuttoncfm); rb2 = (radiobutton) findviewbyid(r.id.radiobuttonac); rb1.setonclicklistener(new radiogroup.onclicklistener() { public void onclick(view v) { edittext e1 = (edittext) findviewbyid(r.id.edittext); string susername1 = e1.gettext().tostring(); if (textutils.isempty(susername1)) { e1.seterror("the item cannot empty."); return; } edittext e2 = (edittext) findviewbyid(r.id.edittext2); string susername2 = e2.gettext().tostring(); if (textutils.isempty(susername2)) { e2.seterror("the item cannot empty."); return; } edittext e3 = (edittext) findviewbyid(r.id.edittext3); string susername3 = e3.gettext().tostring(); if (textutils.isempty(susername3)) { e3.seterror("the item cannot empty."); return; } e1.addtextchangedlistener(new textwatcher() { public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before, int count) { edittext e1 = (edittext)findviewbyid(r.id.edittext); edittext e2 = (edittext)findviewbyid(r.id.edittext2); edittext e3 = (edittext)findviewbyid(r.id.edittext3); volume = double.parsedouble(e1.gettext().tostring()); cfm = double.parsedouble(e2.gettext().tostring()); ac = double.parsedouble(e3.gettext().tostring()); textview t1 = (textview) findviewbyid(r.id.edittext3); volume = double.parsedouble(e1.gettext().tostring()); cfm = double.parsedouble(e2.gettext().tostring()); ac = cfm * 60 / volume; t1.settext(double.tostring((double) math.round(ac * 100000) / 100000)); } }); e2.addtextchangedlistener(new textwatcher() { public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before, int count) { edittext e1 = (edittext)findviewbyid(r.id.edittext); edittext e2 = (edittext)findviewbyid(r.id.edittext2); edittext e3 = (edittext)findviewbyid(r.id.edittext3); volume = double.parsedouble(e1.gettext().tostring()); cfm = double.parsedouble(e2.gettext().tostring()); ac = double.parsedouble(e3.gettext().tostring()); textview t1 = (textview) findviewbyid(r.id.edittext3); volume = double.parsedouble(e1.gettext().tostring()); cfm = double.parsedouble(e2.gettext().tostring()); ac = cfm * 60 / volume; t1.settext(double.tostring((double) math.round(ac * 100000) / 100000)); } }); }}); rb2.setonclicklistener(new radiogroup.onclicklistener() { public void onclick(view v) { edittext e1 = (edittext)findviewbyid(r.id.edittext); string susername1 = e1.gettext().tostring(); if(textutils.isempty(susername1)) { e1.seterror("the item cannot empty."); return; } edittext e2 = (edittext)findviewbyid(r.id.edittext2); string susername2 = e2.gettext().tostring(); if(textutils.isempty(susername2)) { e2.seterror("the item cannot empty."); return; } edittext e3 = (edittext)findviewbyid(r.id.edittext3); string susername3 = e3.gettext().tostring(); if(textutils.isempty(susername3)) { e3.seterror("the item cannot empty."); return; } e1.addtextchangedlistener(new textwatcher() { public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before, int count) { edittext e1 = (edittext)findviewbyid(r.id.edittext); edittext e2 = (edittext)findviewbyid(r.id.edittext2); edittext e3 = (edittext)findviewbyid(r.id.edittext3); volume = double.parsedouble(e1.gettext().tostring()); cfm = double.parsedouble(e2.gettext().tostring()); ac = double.parsedouble(e3.gettext().tostring()); textview t2 = (textview)findviewbyid(r.id.edittext2); volume = double.parsedouble(e1.gettext().tostring()); ac = double.parsedouble(e3.gettext().tostring()); cfm = ac * volume / 60; t2.settext(double.tostring((double) math.round(cfm * 100000) / 100000)); } }); e3.addtextchangedlistener(new textwatcher() { public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before, int count) { edittext e1 = (edittext)findviewbyid(r.id.edittext); edittext e2 = (edittext)findviewbyid(r.id.edittext2); edittext e3 = (edittext)findviewbyid(r.id.edittext3); volume = double.parsedouble(e1.gettext().tostring()); cfm = double.parsedouble(e2.gettext().tostring()); ac = double.parsedouble(e3.gettext().tostring()); textview t2 = (textview)findviewbyid(r.id.edittext2); volume = double.parsedouble(e1.gettext().tostring()); ac = double.parsedouble(e3.gettext().tostring()); cfm = ac * volume / 60; t2.settext(double.tostring((double) math.round(cfm * 100000) / 100000)); } }); } }); }
your textwatcher that's watching input of r.id.edittext3
modifying text of r.id.edittext2
, in turn modifying r.id.edittext3
. through that, you'll infinite calls ontextchanged(...)
.
Comments
Post a Comment