0

我使用下面的代码来获取用户的当前位置。在这段代码中,我试图获取一个人所在位置的纬度和经度。我使用了一个按钮“ GETLATLON ”,并且我希望在布局中使用的框中的纬度经度。但是程序正在强行关闭。你能告诉我我应该做什么更正才能在模拟器上显示。

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;
     }
}

下面是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

单击模拟器屏幕上的 GETLATLON 按钮后,下面是 logcat

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
4

1 回答 1

0

我认为这是由于Android由于某种原因无法找到org.restlet.resource.ClientResource。如果这是单独的库,则已将其添加到您的项目构建路径中。

于 2013-03-18T10:36:02.260 回答