0

我正在尝试从我的代码中的地图视图加载 googlemaps。

在活动尝试加载的那一刻,将产生以下错误,如下所示在 LogCat 中。

我在我的代码中看不到任何明显的东西,我没有导入任何额外的 JAR 文件,因为我使用 dosent 的教程说在这个简单的阶段需要它们。

希望有些人可以看到我哪里出错了。:

来自 logcat 的错误:

02-17 19:47:01.889: E/AndroidRuntime(300): FATAL EXCEPTION: main
02-17 19:47:01.889: E/AndroidRuntime(300): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.mapdb/com.example.mapdb.GoogleMapsActivity}: java.lang.ClassNotFoundException: com.example.mapdb.GoogleMapsActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.example.mapdb-2.apk]
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.os.Looper.loop(Looper.java:123)
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-17 19:47:01.889: E/AndroidRuntime(300):  at java.lang.reflect.Method.invokeNative(Native Method)
02-17 19:47:01.889: E/AndroidRuntime(300):  at java.lang.reflect.Method.invoke(Method.java:521)
02-17 19:47:01.889: E/AndroidRuntime(300):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-17 19:47:01.889: E/AndroidRuntime(300):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-17 19:47:01.889: E/AndroidRuntime(300):  at dalvik.system.NativeStart.main(Native Method)
02-17 19:47:01.889: E/AndroidRuntime(300): Caused by: java.lang.ClassNotFoundException: com.example.mapdb.GoogleMapsActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.example.mapdb-2.apk]
02-17 19:47:01.889: E/AndroidRuntime(300):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
02-17 19:47:01.889: E/AndroidRuntime(300):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
02-17 19:47:01.889: E/AndroidRuntime(300):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-17 19:47:01.889: E/AndroidRuntime(300):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
02-17 19:47:01.889: E/AndroidRuntime(300):  ... 11 more

显现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdb"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".GoogleMapsActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <uses-library android:name="com.google.android.maps" />
</application>
</manifest>

主要活动类:

package com.example.mapdb;

import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //fetch the map view from the layout
    MapView mapView = (MapView) findViewById(R.id.mapview);

    //make available zoom controls
    mapView.setBuiltInZoomControls(true);
}

@Override
protected boolean isRouteDisplayed() {

    return false;

 }
}

activity_main.xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

   <com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:apiKey="0xxxxxxxxxxxxxxxxxxxxg"
    android:clickable="true" />
</LinearLayout>
4

1 回答 1

2

在您的 Java 代码中,您有:

public class MainActivity extends MapActivity

在您的清单中,您有:

<activity
    android:name=".GoogleMapsActivity"

MainActivity不是GoogleMapsActivity。请通过重命名类或编辑清单来同步这两个值。

于 2013-02-17T20:00:45.943 回答