我知道这个问题已被提出,但没有一个解决方案对我有帮助。我是Android开发的新手,我正在尝试在我的应用程序中加载地图。但我得到以下例外:
12-12 12:37:26.542: E/AndroidRuntime(19513): FATAL EXCEPTION: main
12-12 12:37:26.542: E/AndroidRuntime(19513): java.lang.RuntimeException: Unable to start activity : android.view.InflateException: Binary XML file line #57: Error inflating class fragment
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.ActivityThread.access$600(ActivityThread.java:149)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.os.Looper.loop(Looper.java:153)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.ActivityThread.main(ActivityThread.java:4987)
12-12 12:37:26.542: E/AndroidRuntime(19513): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 12:37:26.542: E/AndroidRuntime(19513): at java.lang.reflect.Method.invoke(Method.java:511)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
12-12 12:37:26.542: E/AndroidRuntime(19513): at dalvik.system.NativeStart.main(Native Method)
12-12 12:37:26.542: E/AndroidRuntime(19513): Caused by: android.view.InflateException: Binary XML file line #57: Error inflating class fragment
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:260)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.Activity.setContentView(Activity.java:1867)
12-12 12:37:26.542: E/AndroidRuntime(19513): at
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.Activity.performCreate(Activity.java:5020)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
12-12 12:37:26.542: E/AndroidRuntime(19513): ... 11 more
12-12 12:37:26.542: E/AndroidRuntime(19513): Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
12-12 12:37:26.542: E/AndroidRuntime(19513): <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
12-12 12:37:26.542: E/AndroidRuntime(19513): <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
12-12 12:37:26.542: E/AndroidRuntime(19513): <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
12-12 12:37:26.542: E/AndroidRuntime(19513): at maps.af.cf.a(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at maps.af.ay.a(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at maps.af.al.a(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at maps.af.be.a(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at maps.af.bd.a(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at cmj.onTransact(SourceFile:107)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.os.Binder.transact(Binder.java:326)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.google.android.gms.dynamic.a$4.b(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
12-12 12:37:26.542: E/AndroidRuntime(19513): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-12 12:37:26.542: E/AndroidRuntime(19513): ... 21 more
这是我的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<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" >
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDTSCB95Kz4Jndj5AxBUGPE_I0g9DwNjsI" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="x.y.z.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="x.y.z.BookCabActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
以下是xml中的片段块:
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/pickLoc" />
和Activity.java如下:
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class BookCabActivity extends FragmentActivity{
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.book_cab);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
map= fm.getMap();
}
}
请帮我解决这个问题。我坚持这个,不能前进。抱歉我的英语不好。 :)
答案 0 :(得分:3)
Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
在清单
中添加以下内容 <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"/>
检查指定权限
下的文档编辑:
答案 1 :(得分:1)
尝试在manifest.xml中添加它
<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"/>