android開発者ガイドとyoutubeガイドを確認しました。また、ここで尋ねられた他の同様の質問も確認しましたが、Nexus7にマップをロードできません。
後で自分の地域の地元のお店やサービスを強調するアプリケーションを作成しようとしていますが、最初に地図を読み込むことができる必要があります。デバイスで実行しようとすると、「残念ながら、[アプリ]が停止しました」という通知が表示されます。
これが私のコードです:
マニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bloomingtonfirst"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.bloomingtonfirst.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission
android:name="com.example.bloomingtonfirst.permission.MAPS_RECEIVE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"/>
<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"/>
<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"/>
<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" >
<meta-data
android:name="come.google.android.maps.v2.API_KEY"
android:value="super_secret_key"/>
<activity
android:name="com.example.bloomingtonfirst.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>
</application>
</manifest>
activity_main.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"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
mainactivity.java:
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity{
SupportMapFragment mMap;
GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMap = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = mMap.getMap();
}
}
logcat:
03-19 16:25:55.620: D/dalvikvm(16340): GC_CONCURRENT freed 256K, 6% free 7463K/7864K, paused 2ms+1ms, total 22ms
03-19 16:25:55.660: D/AndroidRuntime(16340): Shutting down VM
03-19 16:25:55.660: W/dalvikvm(16340): threadid=1: thread exiting with uncaught exception (group=0x40d26930)
03-19 16:25:55.660: E/AndroidRuntime(16340): FATAL EXCEPTION: main
03-19 16:25:55.660: E/AndroidRuntime(16340): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bloomingtonfirst/com.example.bloomingtonfirst.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.os.Looper.loop(Looper.java:137)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-19 16:25:55.660: E/AndroidRuntime(16340): at java.lang.reflect.Method.invokeNative(Native Method)
03-19 16:25:55.660: E/AndroidRuntime(16340): at java.lang.reflect.Method.invoke(Method.java:511)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-19 16:25:55.660: E/AndroidRuntime(16340): at dalvik.system.NativeStart.main(Native Method)
03-19 16:25:55.660: E/AndroidRuntime(16340): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.Activity.setContentView(Activity.java:1881)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.example.bloomingtonfirst.MainActivity.onCreate(MainActivity.java:17)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.Activity.performCreate(Activity.java:5104)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-19 16:25:55.660: E/AndroidRuntime(16340): ... 11 more
03-19 16:25:55.660: E/AndroidRuntime(16340): Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
03-19 16:25:55.660: E/AndroidRuntime(16340): at maps.z.ab.a(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at maps.z.ab.a(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at maps.z.ab.a(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at maps.z.ag.a(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at maps.z.ag.a(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at maps.z.bw.a(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at maps.z.r.onCreateView(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.os.Binder.transact(Binder.java:310)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.google.android.gms.internal.e$4.a(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.google.android.gms.internal.e.a(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.google.android.gms.internal.e.onCreateView(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
03-19 16:25:55.660: E/AndroidRuntime(16340): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-19 16:25:55.660: E/AndroidRuntime(16340): ... 21 more
どんな試みでも大歓迎です。