我正在尝试进行Google
Maps活动,但是出现LogCat错误,我的应用程序崩溃了。注册API密钥时,我使用了android提供的编码,所以我不知道为什么它不起作用。我需要帮助解决此问题。
LogCat
08-10 11:04:38.854: W/dalvikvm(702): Unable to resolve superclass of Lcom/maps/google/Main; (402)
08-10 11:04:38.854: W/dalvikvm(702): Link of class 'Lcom/maps/google/Main;' failed
08-10 11:04:38.854: D/AndroidRuntime(702): Shutting down VM
08-10 11:04:38.854: W/dalvikvm(702): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
08-10 11:04:38.874: E/AndroidRuntime(702): FATAL EXCEPTION: main
08-10 11:04:38.874: E/AndroidRuntime(702): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.maps.google/com.maps.google.Main}: java.lang.ClassNotFoundException: com.maps.google.Main
08-10 11:04:38.874: E/AndroidRuntime(702): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
08-10 11:04:38.874: E/AndroidRuntime(702): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-10 11:04:38.874: E/AndroidRuntime(702): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-10 11:04:38.874: E/AndroidRuntime(702): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-10 11:04:38.874: E/AndroidRuntime(702): at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 11:04:38.874: E/AndroidRuntime(702): at android.os.Looper.loop(Looper.java:137)
08-10 11:04:38.874: E/AndroidRuntime(702): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-10 11:04:38.874: E/AndroidRuntime(702): at java.lang.reflect.Method.invokeNative(Native Method)
08-10 11:04:38.874: E/AndroidRuntime(702): at java.lang.reflect.Method.invoke(Method.java:511)
08-10 11:04:38.874: E/AndroidRuntime(702): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-10 11:04:38.874: E/AndroidRuntime(702): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-10 11:04:38.874: E/AndroidRuntime(702): at dalvik.system.NativeStart.main(Native Method)
08-10 11:04:38.874: E/AndroidRuntime(702): Caused by: java.lang.ClassNotFoundException: com.maps.google.Main
08-10 11:04:38.874: E/AndroidRuntime(702): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
08-10 11:04:38.874: E/AndroidRuntime(702): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-10 11:04:38.874: E/AndroidRuntime(702): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-10 11:04:38.874: E/AndroidRuntime(702): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
08-10 11:04:38.874: E/AndroidRuntime(702): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
08-10 11:04:38.874: E/AndroidRuntime(702): ... 11 more
XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.maps.MapView
android:id="@+id/MView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="02ooeHTBsCB6ez4yyEGFEyiuNCz5hTHubgxBMfg" />
</RelativeLayout>
Java文件
package com.maps.google;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class Main extends MapActivity {
MapView map;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = (MapView)findViewById(R.id.MView);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
<uses-library
在manifest
文件中添加这样的内容。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package.name">
...
<application android:name="MyApplication" >
<uses-library android:name="com.google.android.maps" />
...
</application>
...
</manifest>