私はアンドロイド API v2 を使用してマップ ビューに取り組んでいます。このチュートリアルに従っています。彼がチュートリアルで説明したことに従いましたが、それでも致命的な例外が発生します。ここに、log cat を使用した私の 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"
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=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
ログキャット:
05-08 10:38:22.121: E/AndroidRuntime(954): FATAL EXCEPTION: main
05-08 10:38:22.121: E/AndroidRuntime(954): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map/com.example.map.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.os.Looper.loop(Looper.java:137)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-08 10:38:22.121: E/AndroidRuntime(954): at dalvik.system.NativeStart.main(Native Method)
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.setContentView(Activity.java:1881)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.example.map.MainActivity.onCreate(MainActivity.java:12)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.performCreate(Activity.java:5104)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 11 more
05-08 10:38:22.121: E/AndroidRuntime(954): 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
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:592)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:560)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.onCreateView(Activity.java:4709)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 21 more
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: /data/app/com.example.map-2.apk
05-08 10:38:22.121: E/AndroidRuntime(954): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:582)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 24 more
そして、私のマニフェストは次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.map.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDSW0CfwDN0LyrF8PBeihEjrAkj25TDhUQ" />
</application>
</manifest>