0

As I understood (from here) the LoopJ AndroidAsyncHttp does not uses the UI Thread, therefore i can execute its methods in the Main Thread. but when i intilize a new instance of AsyncHttpClient the app crashes (exception: java.lang.IllegalStateException: Could not execute method of the activity )

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
Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
Gil
  • 97
  • 2
  • 10
  • plz put your `AsyncHttpClient` code – Rustam Sep 25 '14 at 17:30
  • 2
    check your `logcat` `09-25 09:58:07.477: E/AndroidRuntime(2514): Caused by: java.lang.NoClassDefFoundError: com.loopj.android.http.AsyncHttpClient` – Rustam Sep 25 '14 at 17:34
  • Looks like you are missing a dependency. See [this](http://stackoverflow.com/questions/20327940/android-no-class-def-found-error-for-com-loopj-android-http-asynchttpclient) or [this](http://stackoverflow.com/questions/16980159/no-class-def-found-error-android) – codeMagic Sep 25 '14 at 17:34

2 Answers2

0

You're getting a NoClassDefFoundError for com.loopj.android.http.AsyncHttpClient

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.

Michael Krause
  • 4,689
  • 1
  • 21
  • 25
0

I had to move the jar file to the "libs" folder and then add the jar to the project... thanks everyone!

Gil
  • 97
  • 2
  • 10