當(dāng)我按下登錄按鈕時(shí),此錯(cuò)誤會導(dǎo)致我的應(yīng)用程序崩潰。發(fā)生的錯(cuò)誤如下。我嘗試了很多事情,例如將發(fā)送函數(shù)放在另一個(gè)腳本中。我也嘗試過在另一個(gè) ide(如 eclipse)中單獨(dú)運(yùn)行 send 函數(shù),沒有錯(cuò)誤。我是 java 新手,花了幾個(gè)小時(shí)試圖解決這個(gè)問題。錯(cuò)誤是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貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊
在 android 中,您不能在主線程上運(yùn)行網(wǎng)絡(luò)操作,例如在另一個(gè)線程中運(yùn)行這些任務(wù):
Thread mThread = new Thread(new Runnable() {
@Override
public void run() {
try {
//Put your code here
} catch (Exception e) {
e.printStackTrace();
}
}
});
mThread.start
添加回答
舉報(bào)
0/150
提交
取消