Android restlet web services - Could not find method org.json.JSONException.<init>, referenced from method org.restlet.ext.json.JsonRepresentation.getJsonText

  • Replies:0
shab
  • Forum posts: 1

Mar 20, 2013, 8:30:43 AM via Website

Hi,

I am working on a project on navigation.
For that sake, I am trying to get the latitude and longitude of the current location of the WiFi enabled device.
But I am unable to view the expected output on the emulator. When I click LatLon button on the emulator screen, it gives a pop up message saying that "The application is unexpectedly closing". Force Close.
I checked the logcat window, it throws the exception " Could not find method org.json.JSONException.<init>, referenced from method org.restlet.ext.json.JsonRepresentation.getJsonText"
Initially, I have added the jar files 'C:\restlet-jse-2.0.10\restlet-jse-2.0.10\lib\org.json_2.0\org.json.jar;C:\restlet-jse-2.0.10\restlet-jse-2.0.10\lib\org.restlet.ext.json.jar;C:\restlet-jse-2.0.10\restlet-jse-2.0.10\lib\org.restlet.jar;" using add external jars. after going through some posts, I have changed the order of the jar files. Finally, I added the jar files directly in the lib folder of our project. But nothing is working.
I have attached the code.
1package com.android.navigation;
2
3import android.os.Bundle;
4import android.app.Activity;
5import android.view.View;
6import android.widget.EditText;
7import org.json.JSONObject;
8import org.restlet.data.ChallengeScheme;
9import org.restlet.ext.json.JsonRepresentation;
10import org.restlet.resource.ClientResource;
11
12
13public class MainActivity extends Activity {
14 private final static String BASE_URL = "xxx";
15 private final static String SITE_ID = "1yy";// Your site ID here
16 private final static String STATION_MAC = "{mac};// The station's MAC address
17
18 private final static String USERNAME = "user";// Your username
19 private final static String PASSWORD = "pw";// Your password
20 EditText text1;
21 EditText text2;
22
23 @Override
24 protected void onCreate(Bundle savedInstanceState) {
25 super.onCreate(savedInstanceState);
26 setContentView(R.layout.activity_main);
27
28 }
29 public void onClick(View view) throws Exception {
30 double lat;
31 double lon;
32 text1 = (EditText) findViewById(R.id.editText1);
33 text2 = (EditText) findViewById(R.id.editText2);
34
35 String url = BASE_URL + "sites/" + SITE_ID + "/stations/" + STATION_MAC + "/";
36 ClientResource itsClient = new ClientResource(url);
37 itsClient.setChallengeResponse(ChallengeScheme.HTTP_BASIC, USERNAME, PASSWORD);
38 // Retrieve and parse the JSON representation
39 JsonRepresentation jsonRep = new JsonRepresentation(itsClient.get());
40 JSONObject jsonObj = jsonRep.getJsonObject();
41 // Output results
42 lat=jsonObj.getJSONObject("loc").getDouble("lat");
43 lon=jsonObj.getJSONObject("loc").getDouble("lng");
44 switch (view.getId()) {
45 case R.id.button1:
46
47 String lats = Double.toString(lat);
48 text1.setText(lats);
49 String lons = Double.toString(lon);
50 text2.setText(lons);
51 break;
52 }
53 }
54
55}

Below is the logcat
03-18 14:09:15.639: E/dalvikvm(563): Could not find class 'org.restlet.resource.ClientResource', referenced from method com.android.navigation.MainActivity.onClick
03-18 14:09:15.639: W/dalvikvm(563): VFY: unable to resolve new-instance 546 (Lorg/restlet/resource/ClientResource;) in Lcom/android/navigation/MainActivity;
03-18 14:09:15.639: D/dalvikvm(563): VFY: replacing opcode 0x22 at 0x0002
03-18 14:09:15.671: D/dalvikvm(563): VFY: dead code 0x0004-004f in Lcom/android/navigation/MainActivity;.onClick (Landroid/view/View;)V
03-18 14:25:12.149: D/AndroidRuntime(563): Shutting down VM
03-18 14:25:12.149: W/dalvikvm(563): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-18 14:25:12.232: E/AndroidRuntime(563): FATAL EXCEPTION: main
03-18 14:25:12.232: E/AndroidRuntime(563): java.lang.IllegalStateException: Could not execute method of the activity
03-18 14:25:12.232: E/AndroidRuntime(563): at android.view.View$1.onClick(View.java:2144)
03-18 14:25:12.232: E/AndroidRuntime(563): at android.view.View.performClick(View.java:2485)
03-18 14:25:12.232: E/AndroidRuntime(563): at android.view.View$PerformClick.run(View.java:9080)
03-18 14:25:12.232: E/AndroidRuntime(563): at android.os.Handler.handleCallback(Handler.java:587)
03-18 14:25:12.232: E/AndroidRuntime(563): at android.os.Handler.dispatchMessage(Handler.java:92)
03-18 14:25:12.232: E/AndroidRuntime(563): at android.os.Looper.loop(Looper.java:123)
03-18 14:25:12.232: E/AndroidRuntime(563): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-18 14:25:12.232: E/AndroidRuntime(563): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 14:25:12.232: E/AndroidRuntime(563): at java.lang.reflect.Method.invoke(Method.java:507)
03-18 14:25:12.232: E/AndroidRuntime(563): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-18 14:25:12.232: E/AndroidRuntime(563): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-18 14:25:12.232: E/AndroidRuntime(563): at dalvik.system.NativeStart.main(Native Method)
03-18 14:25:12.232: E/AndroidRuntime(563): Caused by: java.lang.reflect.InvocationTargetException
03-18 14:25:12.232: E/AndroidRuntime(563): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 14:25:12.232: E/AndroidRuntime(563): at java.lang.reflect.Method.invoke(Method.java:507)
03-18 14:25:12.232: E/AndroidRuntime(563): at android.view.View$1.onClick(View.java:2139)
03-18 14:25:12.232: E/AndroidRuntime(563): ... 11 more
03-18 14:25:12.232: E/AndroidRuntime(563): Caused by: java.lang.NoClassDefFoundError: org.restlet.resource.ClientResource
03-18 14:25:12.232: E/AndroidRuntime(563): at com.android.navigation.MainActivity.onClick(MainActivity.java:35)
03-18 14:25:12.232: E/AndroidRuntime(563): ... 14 more
03-18 14:25:16.851: I/Process(563): Sending signal. PID: 563 SIG: 9

Reply