我試圖從我的代碼中的mapview加載googlemaps。無法從活動啓動mapview
當活動嘗試加載時,正在生成以下錯誤,如下面的LogCat中所示。
我看不出任何明顯的內容,我沒有導入任何額外的JAR文件作爲教程即時通訊使用劑量說,他們在這個簡單的階段需要。
希望一些能看到林從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;
}
}
活性狀況ty_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>
自2012年12月起,您的APIkey已被折舊。您必須使用Google Maps API v2實施新方法。請閱讀[本官方文檔](https://developers.google.com/maps/documentation/android/v1/)。 – BBonDoo 2013-02-22 10:39:34