java - android:onclick method doesn't work -
xml code:
<button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="invia" android:clickable="true" android:onclick="onclick1" android:id="@+id/invia" />
java code:
import android.app.activity; import android.content.intent; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.toast; import com.android.volley.request; import com.android.volley.requestqueue; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.toolbox.stringrequest; import com.android.volley.toolbox.volley; import java.util.hashmap; import java.util.locale; import java.util.map; public class creazionesondaggio extends appcompatactivity { string url; private edittext titolo; private edittext sceltaa; private edittext sceltab; private edittext sceltac; private button invio; private edittext server; @override protected void oncreate(bundle savedinstancestate) { titolo = (edittext) findviewbyid(r.id.titolo); sceltaa = (edittext) findviewbyid(r.id.a); sceltab = (edittext) findviewbyid(r.id.b); sceltac = (edittext) findviewbyid(r.id.c); server= (edittext) findviewbyid(r.id.server); invio = (button) findviewbyid(r.id.invia); // invio.setonclicklistener(this); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_creazione_sondaggio); } private void inviodati() { ...... } public void onclick1(view v) { toast.maketext(creazionesondaggio.this, "ok", toast.length_long).show(); inviodati(); } }
error:
process: com.example.rober.registrazione, pid: 21261 java.lang.illegalstateexception: not execute method android:onclick @ android.support.v7.app.appcompatviewinflater$declaredonclicklistener.onclick(appcompatviewinflater.java:275) @ android.view.view.performclick(view.java:5210) @ android.view.view$performclick.run(view.java:21288) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5527) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:730) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:620) caused by: java.lang.reflect.invocationtargetexception @ java.lang.reflect.method.invoke(native method) @ android.support.v7.app.appcompatviewinflater$declaredonclicklistener.onclick(appcompatviewinflater.java:270) @ android.view.view.performclick(view.java:5210) @ android.view.view$performclick.run(view.java:21288) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5527) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:730) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:620) caused by: java.lang.nullpointerexception: attempt invoke virtual method 'android.text.editable android.widget.edittext.gettext()' on null object reference @ com.example.rober.registrazione.creazionesondaggio.inviodati(creazionesondaggio.java:48) @ com.example.rober.registrazione.creazionesondaggio.onclick1(creazionesondaggio.java:87) @ java.lang.reflect.method.invoke(native method) @ android.support.v7.app.appcompatviewinflater$declaredonclicklistener.onclick(appcompatviewinflater.java:270) @ android.view.view.performclick(view.java:5210) @ android.view.view$performclick.run(view.java:21288) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5527) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:730) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:620)
how can fix it?
update oncreate method
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_creazione_sondaggio); titolo = (edittext) findviewbyid(r.id.titolo); sceltaa = (edittext) findviewbyid(r.id.a); sceltab = (edittext) findviewbyid(r.id.b); sceltac = (edittext) findviewbyid(r.id.c); server= (edittext) findviewbyid(r.id.server); invio = (button) findviewbyid(r.id.invia); // invio.setonclicklistener(this); }
Comments
Post a Comment