当我按下登录按钮时,此错误会导致我的应用程序崩溃。发生的错误如下。我尝试了很多事情,例如将发送函数放在另一个脚本中。我也尝试过在另一个 ide(如 eclipse)中单独运行 send 函数,没有错误。我是 java 新手,花了几个小时试图解决这个问题。错误是E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.messager, PID: 19051 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390) at android.view.View.performClick(View.java:6614) at android.view.View.performClickInternal(View.java:6591) at android.view.View.access$3100(View.java:786) at android.view.View$PerformClick.run(View.java:25948) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6806) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) at android.view.View.performClick(View.java:6614) at android.view.View.performClickInternal(View.java:6591) at android.view.View.access$3100(View.java:786) at android.view.View$PerformClick.run(View.java:25948) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201)
1 回答
沧海一幻觉
TA贡献1824条经验 获得超5个赞
在 android 中,您不能在主线程上运行网络操作,例如在另一个线程中运行这些任务:
Thread mThread = new Thread(new Runnable() {
@Override
public void run() {
try {
//Put your code here
} catch (Exception e) {
e.printStackTrace();
}
}
});
mThread.start
添加回答
举报
0/150
提交
取消