我正在尝试从代码中的mapview加载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>
答案 0 :(得分:2)
在Java代码中,您有:
public class MainActivity extends MapActivity
在你的清单中,你有:
<activity
android:name=".GoogleMapsActivity"
MainActivity
不是GoogleMapsActivity
。请通过重命名类或编辑清单来同步这两个值。