大家好我为mapView编写了2个类,另一个用于位置设置,我使用alertDialog框让用户在启用GPS之间选择或直接使用意图直接到地图但我遇到错误。任何人都可以帮忙???
这是对话框代码
public void onClick(View arg0) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Click yes TO ENABLE GPS")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, close
// current activity
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 1);
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, just close
// the dialog box and do nothing
//dialog.cancel();
Intent intent = new Intent(MainActivity.this, AndroidGoogleMapsActivity.class);
context.startActivity(intent);
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
这是我得到的错误
09-19 08:28:58.996: W/dalvikvm(440): Unable to resolve superclass of Lcom/mkyong/android/AndroidGoogleMapsActivity; (16)
09-19 08:28:58.996: W/dalvikvm(440): Link of class 'Lcom/mkyong/android/AndroidGoogleMapsActivity;' failed
09-19 08:28:59.004: E/dalvikvm(440): Could not find class 'com.mkyong.android.AndroidGoogleMapsActivity', referenced from method com.mkyong.android.MainActivity$1$2.onClick
09-19 08:28:59.004: W/dalvikvm(440): VFY: unable to resolve const-class 19 (Lcom/mkyong/android/AndroidGoogleMapsActivity;) in Lcom/mkyong/android/MainActivity$1$2;
09-19 08:28:59.004: D/dalvikvm(440): VFY: replacing opcode 0x1c at 0x0008
09-19 08:28:59.014: D/dalvikvm(440): VFY: dead code 0x000a-0018 in Lcom/mkyong/android/MainActivity$1$2;.onClick (Landroid/content/DialogInterface;I)V
09-19 08:29:16.164: D/AndroidRuntime(440): Shutting down VM
09-19 08:29:16.174: W/dalvikvm(440): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-19 08:29:16.254: E/AndroidRuntime(440): FATAL EXCEPTION: main
09-19 08:29:16.254: E/AndroidRuntime(440): java.lang.NoClassDefFoundError: com.mkyong.android.AndroidGoogleMapsActivity
09-19 08:29:16.254: E/AndroidRuntime(440): at com.mkyong.android.MainActivity$1$2.onClick(MainActivity.java:61)
09-19 08:29:16.254: E/AndroidRuntime(440): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
09-19 08:29:16.254: E/AndroidRuntime(440): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 08:29:16.254: E/AndroidRuntime(440): at android.os.Looper.loop(Looper.java:123)
09-19 08:29:16.254: E/AndroidRuntime(440): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-19 08:29:16.254: E/AndroidRuntime(440): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 08:29:16.254: E/AndroidRuntime(440): at java.lang.reflect.Method.invoke(Method.java:521)
09-19 08:29:16.254: E/AndroidRuntime(440): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-19 08:29:16.254: E/AndroidRuntime(440): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-19 08:29:16.254: E/AndroidRuntime(440): at dalvik.system.NativeStart.main(Native Method)
09-19 08:29:18.725: I/Process(440): Sending signal. PID: 440 SIG: 9
我不知道如何解决它
答案 0 :(得分:0)
您是否在清单文件中定义了AndroidGoogleMapsActivity类和地图库?你必须把它放在元素中。
<application ...>
...
<uses-library android:required="true" android:name="com.google.android.maps" />
...
</application>