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.
package com.android.navigation;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.EditText;
import org.json.JSONObject;
import org.restlet.data.ChallengeScheme;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.ClientResource;
public class MainActivity extends Activity {
private final static String BASE_URL = "xxx";
private final static String SITE_ID = "1yy";// Your site ID here
private final static String STATION_MAC = "{mac};// The station's MAC address
private final static String USERNAME = "user";// Your username
private final static String PASSWORD = "pw";// Your password
EditText text1;
EditText text2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view) throws Exception {
double lat;
double lon;
text1 = (EditText) findViewById(R.id.editText1);
text2 = (EditText) findViewById(R.id.editText2);
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-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
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.
package com.android.navigation;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.EditText;
import org.json.JSONObject;
import org.restlet.data.ChallengeScheme;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.ClientResource;
public class MainActivity extends Activity {
private final static String BASE_URL = "xxx";
private final static String SITE_ID = "1yy";// Your site ID here
private final static String STATION_MAC = "{mac};// The station's MAC address
private final static String USERNAME = "user";// Your username
private final static String PASSWORD = "pw";// Your password
EditText text1;
EditText text2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view) throws Exception {
double lat;
double lon;
text1 = (EditText) findViewById(R.id.editText1);
text2 = (EditText) findViewById(R.id.editText2);
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-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
V03-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