0

I am newbie to android RESTlet. I am trying to connect to url and get the information upon button click. But I am getting the error " java.lang.IllegalStateException: Could not execute method of the activity" and " Caused by: java.lang.reflect.InvocationTargetException". Please let me know how to resolve this.

private EditText text1;
private EditText text2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text1 = (EditText) findViewById(R.id.editText1);
text2 = (EditText) findViewById(R.id.editText2);
}
public void onClick(View view) throws Exception {
double lat;
double lon;
String url = BASE_URL + "sites/" + SITE_ID + "/stations/" + STATION_MAC + "/";
ClientResource itsClient = new ClientResource(url);
itsClient.setChallengeResponse(ChallengeScheme.HTTP_BASIC, USERNAME, PASSWORD);

// Retrieve and parse the JSON representation
JsonRepresentation jsonRep = new JsonRepresentation(itsClient.get());
JSONObject jsonObj = jsonRep.getJsonObject();

// Output results
lat=jsonObj.getJSONObject("loc").getDouble("lat");
lon=jsonObj.getJSONObject("loc").getDouble("lng");

switch (view.getId()) {
    case R.id.button1:
    String lats = Double.toString(lat);
    text1.setText(lats);
    String lons = Double.toString(lon);
    text2.setText(lons);
    break;
 }

}

Below is the logcat:

03-22 18:25:38.834: E/Trace(755): error opening trace file: No such file or directory (2)
03-22 18:25:39.064: E/dalvikvm(755): Could not find class 'org.restlet.resource.ClientResource', referenced from method com.android.navigation.MainActivity.onClick
03-22 18:25:39.064: W/dalvikvm(755): VFY: unable to resolve new-instance 546 (Lorg/restlet/resource/ClientResource;) in Lcom/android/navigation/MainActivity;
03-22 18:25:39.076: D/dalvikvm(755): VFY: replacing opcode 0x22 at 0x0018
03-22 18:25:39.096: D/dalvikvm(755): DexOpt: unable to opt direct call 0x0d80 at 0x1a in Lcom/android/navigation/MainActivity;.onClick
03-22 18:25:39.126: D/dalvikvm(755): DexOpt: unable to opt direct call 0x0d7e at 0x2c in Lcom/android/navigation/MainActivity;.onClick
03-22 18:25:40.036: I/Choreographer(755): Skipped 40 frames!  The application may be doing too much work on its main thread.
03-22 18:25:40.114: D/gralloc_goldfish(755): Emulator without GPU emulation detected.
03-22 18:25:58.035: I/Choreographer(755): Skipped 210 frames!  The application may be doing too much work on its main thread.
03-22 18:26:00.554: D/AndroidRuntime(755): Shutting down VM
03-22 18:26:00.564: W/dalvikvm(755): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
03-22 18:26:00.654: E/AndroidRuntime(755): FATAL EXCEPTION: main
03-22 18:26:00.654: E/AndroidRuntime(755): java.lang.IllegalStateException: Could not execute method of the activity
03-22 18:26:00.654: E/AndroidRuntime(755):  at android.view.View$1.onClick(View.java:3591)
03-22 18:26:00.654: E/AndroidRuntime(755):  at android.view.View.performClick(View.java:4084)
03-22 18:26:00.654: E/AndroidRuntime(755):  at android.view.View$PerformClick.run(View.java:16966)
03-22 18:26:00.654: E/AndroidRuntime(755):  at android.os.Handler.handleCallback(Handler.java:615)
03-22 18:26:00.654: E/AndroidRuntime(755):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-22 18:26:00.654: E/AndroidRuntime(755):  at android.os.Looper.loop(Looper.java:137)
03-22 18:26:00.654: E/AndroidRuntime(755):  at android.app.ActivityThread.main(ActivityThread.java:4745)
03-22 18:26:00.654: E/AndroidRuntime(755):  at java.lang.reflect.Method.invokeNative(Native Method)
03-22 18:26:00.654: E/AndroidRuntime(755):  at java.lang.reflect.Method.invoke(Method.java:511)
03-22 18:26:00.654: E/AndroidRuntime(755):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-22 18:26:00.654: E/AndroidRuntime(755):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-22 18:26:00.654: E/AndroidRuntime(755):  at dalvik.system.NativeStart.main(Native Method)
03-22 18:26:00.654: E/AndroidRuntime(755): Caused by: java.lang.reflect.InvocationTargetException
03-22 18:26:00.654: E/AndroidRuntime(755):  at java.lang.reflect.Method.invokeNative(Native Method)
03-22 18:26:00.654: E/AndroidRuntime(755):  at java.lang.reflect.Method.invoke(Method.java:511)
03-22 18:26:00.654: E/AndroidRuntime(755):  at android.view.View$1.onClick(View.java:3586)
03-22 18:26:00.654: E/AndroidRuntime(755):  ... 11 more
03-22 18:26:00.654: E/AndroidRuntime(755): Caused by: java.lang.NoClassDefFoundError: org.restlet.resource.ClientResource
03-22 18:26:00.654: E/AndroidRuntime(755):  at com.android.navigation.MainActivity.onClick(MainActivity.java:36)
03-22 18:26:00.654: E/AndroidRuntime(755):  ... 14 more
03-22 18:26:05.975: I/Process(755): Sending signal. PID: 755 SIG: 9

Initially, I have added restlet jar files using "Add External jar files". Later, after googling, I added those jar files in Libs folder and added them using Add Jar files in Configure Build Path. When I tried that method, I got an error saying "No command output when running: 'am start -n .............. What is the correct way to add jar files? How should I resolve this issue?

user1473912
  • 79
  • 1
  • 10

1 Answers1

3
Caused by: Unauthorized (401) - Unauthorized

So your error is obvious. You are trying to make request on some Server but most likely you provided incorrect login and password with caused 401 unauthorized access.

Make sure you pass correct LOGIN and PASSWORD.

Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
  • Sajmon, I had traced out the 401 error and changed the login and password. But still, getting the error "java-lang-illegalstateexception-could-not-execute-method-of-the-activity" – user1473912 Mar 22 '13 at 12:56
  • @user1473912 now you have error NoClassDefFound. check [this link please](http://javarevisited.blogspot.cz/2011/06/noclassdeffounderror-exception-in.html) – Simon Dorociak Mar 22 '13 at 13:04
  • java.lang.reflect.InvocationTargetException and java.lang.NoClassDefFoundError: org.restlet.resource.ClientResource are the causes of the errors. But I am not knowing how to resolve them. – user1473912 Mar 22 '13 at 13:21
  • @user1473912 here you are next examples how to fix it: [here](http://juddsolutions.blogspot.cz/2008/06/tip-causes-of-javalangclassnotfoundexce.html), [here](http://stackoverflow.com/questions/8265419/caused-by-java-lang-noclassdeffounderror) or [here](http://javarevisited.blogspot.cz/2011/06/noclassdeffounderror-exception-in.html) you need read it not only "see" i just wrote you same things. – Simon Dorociak Mar 22 '13 at 13:46