0

ランタイム例外が発生し、アプリがクラッシュします。ご協力をお願いします。本当にありがとうございました!Google Apis 18 エミュレーターと android デバイス 4.1 の両方を使用しました。また、Google Play サービスをインポートし、Google api v2 を使用しています。そのオプションは、Gmail のキー セクションでもオンになっています。

ログキャット、

 09-10 18:37:47.890: E/AndroidRuntime(23014): FATAL EXCEPTION: main
09-10 18:37:47.890: E/AndroidRuntime(23014): java.lang.RuntimeException: Unable to      start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.os.Looper.loop(Looper.java:137)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.ActivityThread.main(ActivityThread.java:4944)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at java.lang.reflect.Method.invokeNative(Native Method)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at java.lang.reflect.Method.invoke(Method.java:511)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at dalvik.system.NativeStart.main(Native Method)
09-10 18:37:47.890: E/AndroidRuntime(23014): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class fragment
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:318)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.Activity.setContentView(Activity.java:1924)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.example.test.MainActivity.onCreate(MainActivity.java:17)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.Activity.performCreate(Activity.java:5188)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
09-10 18:37:47.890: E/AndroidRuntime(23014):    ... 11 more
09-10 18:37:47.890: E/AndroidRuntime(23014): 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
09-10 18:37:47.890: E/AndroidRuntime(23014):    at maps.ag.bb.a(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at maps.ag.bb.a(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at maps.ag.an.a(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at maps.ag.bi.a(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at maps.ag.bh.a(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at blf.onTransact(SourceFile:107)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.os.Binder.transact(Binder.java:326)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.google.android.gms.internal.bh$4.b(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.google.android.gms.internal.bh.a(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.google.android.gms.internal.bh.onCreateView(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
09-10 18:37:47.890: E/AndroidRuntime(23014):    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184)
 09-10 18:37:47.890: E/AndroidRuntime(23014):   at     android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
 09-10 18:37:47.890: E/AndroidRuntime(23014):   at      android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:682)
 09-10 18:37:47.890: E/AndroidRuntime(23014):   ... 21 more

ジャバファイル、

 package com.example.test;
 import com.google.android.gms.common.GooglePlayServicesUtil;
 import com.google.android.gms.maps.GoogleMap;
 import com.google.android.gms.maps.SupportMapFragment;
 import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;
 import android.view.Menu;
 import android.widget.Toast;

 public class MainActivity extends FragmentActivity{
protected GoogleMap gMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    gMap = ((SupportMapFragment)    
 getSupportFragmentManager().findFragmentById(R.id.map))
            .getMap();
     if (gMap == null) {
            Toast.makeText(this, "Google Maps not available", 
                Toast.LENGTH_LONG).show();}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

 }

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"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"/>


 </RelativeLayout>

マニフェストファイル、

  <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.test"
  android:versionCode="1"
  android:versionName="1.0" >

  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

   <permission
     android:name="com.example.test.permission.MAPS_RECEIVE"
     android:protectionLevel="signature" />

  <uses-permission android:name="com.example.test.permission.MAPS_RECEIVE" />
  <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-permission android:name="android.permission.ACCESS_WIFI_STATE" />

   <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="com.example.test.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

            <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyCpwkQvt7NFXbprE6QgfT-YQEWWApZ1IDQ" />


        </activity>
  </application>

 </manifest>
4

4 に答える 4

0

API キーを適切な場所に配置してから変更すると、これでうまくいき、アプリでマップが表示されるようになりました。皆さんに本当に感謝しています!

于 2013-09-11T05:34:51.470 に答える