3

我正在尝试进行谷歌地图活动,但出现 LogCat 错误并且我的应用程序崩溃。我注册API密钥时使用了android提供的编码,所以我不知道为什么它不起作用。我需要帮助解决这个问题。

日志猫

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

}
4

3 回答 3

11

在您的文件中添加<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>
于 2012-08-10T15:44:53.747 回答
5

确保您在应用程序清单中包含以下行:

<uses-library android:required="true" android:name="com.google.android.maps" />

并确保它在正确的位置。我的问题(有类似的错误消息)是我把它放在那里,但就像使用权限的东西一样,它就在根元素清单的下面,而实际上,uses-library 元素应该放在应用程序元素下面。如果我不够清楚,请参阅以下部分:从 Sameers 链接配置应用程序清单。

于 2012-08-10T15:51:13.903 回答
0

您是否在项目中包含了谷歌地图类?

您需要将地图 jar 文件添加到您的项目中。

jar 可以在您的 {ANDROID-SDK_HOME}\add-ons\addon_google_apis_google_inc_*\libs目录中找到。

这里还有另外两个问题可能会对您的情况有所帮助。

  1. 我想要获取库为 com-google-android-maps-to-add-my-project
  2. google-maps-android-api-gives-a-noclassdeffounderror
于 2012-08-10T15:39:51.047 回答