0
我是新來的android開發,我只是想在活動中顯示谷歌地圖v2片段。 但是,當將Google地圖片段放入活動時,我總是會收到錯誤消息。 當我從活動中刪除片段對象時,一切正常。我究竟做錯了什麼?謝謝谷歌地圖片段錯誤
MapActivity.java源文件保持不變,由Eclipse SDK中的Android SDK創建。
我的活動:
<LinearLayout 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"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cz.samsula.mapnotes.MapActivity" >
<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map"
android:textSize="20sp" />
<fragment
android:id="@+id/fragment_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.google.android.gms.maps.MapFragment" />
</LinearLayout>
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.samsula.mapnotes"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<permission
android:name="cz.samsula.mapnotes.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapActivity"
android:label="@string/title_activity_map"
android:parentActivityName="cz.samsula.mapnotes" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="cz.samsula.mapnotes" />
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDsytnR6kTgLhFlV-ngy1PyhNTykPHdR5o"/>
</application>
</manifest>
Java源文件保持不變,由Android SDK在Eclipse中創建的。
目錄下載:
10-01 14:45:50.766: I/Choreographer(1709): Skipped 67 frames! The application may be doing too much work on its main thread.
10-01 14:45:50.826: D/gralloc_goldfish(1709): Emulator without GPU emulation detected.
10-01 14:45:53.516: I/Choreographer(1709): Skipped 132 frames! The application may be doing too much work on its main thread.
10-01 14:45:54.636: D/AndroidRuntime(1709): Shutting down VM
10-01 14:45:54.636: W/dalvikvm(1709): threadid=1: thread exiting with uncaught exception (group=0xb2ae4ba8)
10-01 14:45:54.866: E/AndroidRuntime(1709): FATAL EXCEPTION: main
10-01 14:45:54.866: E/AndroidRuntime(1709): Process: cz.samsula.mapnotes, PID: 1709
10-01 14:45:54.866: E/AndroidRuntime(1709): java.lang.RuntimeException: Unable to start activity ComponentInfo{cz.samsula.mapnotes/cz.samsula.mapnotes.MapActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.os.Handler.dispatchMessage(Handler.java:102)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.os.Looper.loop(Looper.java:136)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-01 14:45:54.866: E/AndroidRuntime(1709): at java.lang.reflect.Method.invokeNative(Native Method)
10-01 14:45:54.866: E/AndroidRuntime(1709): at java.lang.reflect.Method.invoke(Method.java:515)
10-01 14:45:54.866: E/AndroidRuntime(1709): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-01 14:45:54.866: E/AndroidRuntime(1709): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-01 14:45:54.866: E/AndroidRuntime(1709): at dalvik.system.NativeStart.main(Native Method)
10-01 14:45:54.866: E/AndroidRuntime(1709): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-01 14:45:54.866: E/AndroidRuntime(1709): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.Activity.setContentView(Activity.java:1929)
10-01 14:45:54.866: E/AndroidRuntime(1709): at cz.samsula.mapnotes.MapActivity.onCreate(MapActivity.java:13)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.Activity.performCreate(Activity.java:5231)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
10-01 14:45:54.866: E/AndroidRuntime(1709): ... 11 more
10-01 14:45:54.866: E/AndroidRuntime(1709): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.Fragment.instantiate(Fragment.java:597)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.Fragment.instantiate(Fragment.java:561)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.Activity.onCreateView(Activity.java:4778)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
10-01 14:45:54.866: E/AndroidRuntime(1709): ... 21 more
10-01 14:45:54.866: E/AndroidRuntime(1709): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/cz.samsula.mapnotes-1.apk"],nativeLibraryDirectories=[/data/app-lib/cz.samsula.mapnotes-1, /system/lib]]
10-01 14:45:54.866: E/AndroidRuntime(1709): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
10-01 14:45:54.866: E/AndroidRuntime(1709): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
10-01 14:45:54.866: E/AndroidRuntime(1709): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
10-01 14:45:54.866: E/AndroidRuntime(1709): at android.app.Fragment.instantiate(Fragment.java:583)
10-01 14:45:54.866: E/AndroidRuntime(1709): ... 24 more