简体   繁体   English

初始化AndroidAsyncHttp时Android应用程序崩溃

[英]Android app crashes when initializing AndroidAsyncHttp

As I understood (from here ) the LoopJ AndroidAsyncHttp does not uses the UI Thread, therefore i can execute its methods in the Main Thread. 据我了解(从此处开始 ),LoopJ AndroidAsyncHttp不使用UI线程,因此我可以在主线程中执行其方法。 but when i intilize a new instance of AsyncHttpClient the app crashes (exception: java.lang.IllegalStateException: Could not execute method of the activity ) 但是当我使用AsyncHttpClient的新实例时,应用程序崩溃(例外:java.lang.IllegalStateException:无法执行该活动的方法)

code : 代码:

public class MainActivity extends ActionBarActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


}

public void Send(View view) {
    EditText editText = (EditText) findViewById(R.id.editText1);
    String str = editText.getText().toString();
    TextView div = (TextView) findViewById(R.id.textView1);
    div.setText(str);
    //crash
    AsyncHttpClient client = new AsyncHttpClient();

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}   
}

Error: 错误:

09-25 09:58:07.427: W/dalvikvm(2514): threadid=1: thread exiting with uncaught exception (group=0xb1cb2b20)
09-25 09:58:07.477: E/AndroidRuntime(2514): FATAL EXCEPTION: main
09-25 09:58:07.477: E/AndroidRuntime(2514): Process: com.example.mysecondapp, PID: 2514
09-25 09:58:07.477: E/AndroidRuntime(2514): java.lang.IllegalStateException: Could not execute method of the activity
09-25 09:58:07.477: E/AndroidRuntime(2514):     at android.view.View$1.onClick(View.java:3823)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at android.view.View.performClick(View.java:4438)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at android.view.View$PerformClick.run(View.java:18422)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at android.os.Handler.handleCallback(Handler.java:733)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at android.os.Handler.dispatchMessage(Handler.java:95)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at android.os.Looper.loop(Looper.java:136)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at android.app.ActivityThread.main(ActivityThread.java:5017)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at java.lang.reflect.Method.invokeNative(Native Method)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at java.lang.reflect.Method.invoke(Method.java:515)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at dalvik.system.NativeStart.main(Native Method)
09-25 09:58:07.477: E/AndroidRuntime(2514): Caused by: java.lang.reflect.InvocationTargetException
09-25 09:58:07.477: E/AndroidRuntime(2514):     at java.lang.reflect.Method.invokeNative(Native Method)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at java.lang.reflect.Method.invoke(Method.java:515)
09-25 09:58:07.477: E/AndroidRuntime(2514):     at android.view.View$1.onClick(View.java:3818)
09-25 09:58:07.477: E/AndroidRuntime(2514):     ... 11 more
09-25 09:58:07.477: E/AndroidRuntime(2514): Caused by: java.lang.NoClassDefFoundError: com.loopj.android.http.AsyncHttpClient
09-25 09:58:07.477: E/AndroidRuntime(2514):     at com.example.mysecondapp.MainActivity.Send(MainActivity.java:46)
09-25 09:58:07.477: E/AndroidRuntime(2514):     ... 14 more

You're getting a NoClassDefFoundError for com.loopj.android.http.AsyncHttpClient 您收到com.loopj.android.http.AsyncHttpClient的NoClassDefFoundError

If you are running from an IDE, make sure to add exported="true" to the classpathentry for android-async-http-1.4.6.jar in your .classpath file. 如果您是从IDE运行的,请确保在.classpath文件中将export =“ true”添加到android-async-http-1.4.6.jar的类路径中。

我必须将jar文件移动到“ libs”文件夹,然后将jar添加到项目中……谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM