java - Android Unfortunately app has stopped? -
this question has reply here:
java.lang.illegalstateexception : not find method onclick handler id_button 4 answersi have create app user inputs , ai responds when input text , press send gives me message "unfortunately, app has stopped".
here code:
here code sending:
<button style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button" android:id="@+id/send_btn" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:onclick="zdenka" />...
here start of .java file:
edittext text, odgbox; string odg; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_my); edittext text = (edittext) findviewbyid(r.id.txt); //user input button btn = (button) findviewbyid(r.id.send_btn); //send button textview output = (textview) findviewbyid(r.id.textview); //ai output }...
and lastly part of java file:
... public void zdenka (textview output, edittext text, string odg) { string text1 = text.tostring().tolowercase(); if (text1 == "živjo") { odg = "Živjo"; } else if (text1 == "zivjo") { odg = "oj"; } else{ odg = "ne razumem."; } output.settext(odg);
thanks help!
what can see code is: need alter method of onclick:
you need replace
public void zdenka (textview output, edittext text, string odg) {...}
with
public void zdenka (view v) {...}
hope helps.
and after this, create sure utilize equals
or equalsignorecase
comparing string squonk said. ==
compare objects, not actual string.
java android xml crash android-studio
No comments:
Post a Comment