xml文件
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mvMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
/>
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prashant.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<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="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" >
<meta-data
android:name="com.google.android.gms.version"
android:value="6587000" />
<!-- android:value="@integer/google_play_services_version" /> -->
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".Main"
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>
logcat的:
02-28 19:56:58.052:E / AndroidRuntime(2857):致命异常:主要 02-28 19:56:58.052:E / AndroidRuntime(2857):进程:com.prashant.maps,PID:2857 02-28 19:56:58.052:E / AndroidRuntime(2857):java.lang.RuntimeException:无法启动活动ComponentInfo {com.prashant.maps / com.prashant.maps.Main}:android.view.InflateException:Binary XML文件行#2:错误膨胀类片段 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.ActivityThread.access $ 800(ActivityThread.java:144) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.os.Handler.dispatchMessage(Handler.java:102) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.os.Looper.loop(Looper.java:135) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.ActivityThread.main(ActivityThread.java:5221) 02-28 19:56:58.052:E / AndroidRuntime(2857):at java.lang.reflect.Method.invoke(Native Method) 02-28 19:56:58.052:E / AndroidRuntime(2857):at java.lang.reflect.Method.invoke(Method.java:372) 02-28 19:56:58.052:E / AndroidRuntime(2857):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899) 02-28 19:56:58.052:E / AndroidRuntime(2857):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 02-28 19:56:58.052:E / AndroidRuntime(2857):引起:android.view.InflateException:二进制XML文件行#2:错误膨胀类片段 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.view.LayoutInflater.inflate(LayoutInflater.java:482) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.view.LayoutInflater.inflate(LayoutInflater.java:414) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.view.LayoutInflater.inflate(LayoutInflater.java:365) 02-28 19:56:58.052:E / AndroidRuntime(2857):at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.Activity.setContentView(Activity.java:2144) 02-28 19:56:58.052:E / AndroidRuntime(2857):at com.prashant.maps.Main.onCreate(Main.java:22) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.Activity.performCreate(Activity.java:5933) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) 02-28 19:56:58.052:E / AndroidRuntime(2857):......还有10个 02-28 19:56:58.052:E / AndroidRuntime(2857):引起:android.app.Fragment $ InstantiationException:无法实例化片段com.google.android.gms.maps.SupportMapFragment:确保类名存在,是public,并且有一个公开的空构造函数 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.Fragment.instantiate(Fragment.java:618) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.Fragment.instantiate(Fragment.java:582) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2108) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.Activity.onCreateView(Activity.java:5282) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733) 02-28 19:56:58.052:E / AndroidRuntime(2857):......还有19个 02-28 19:56:58.052:E / AndroidRuntime(2857):引起:java.lang.ClassNotFoundException:未找到类&#34; com.google.android.gms.maps.SupportMapFragment&#34;在路径上:DexPathList [[zip文件&#34; /system/framework/com.google.android.maps.jar" ;, zip文件&#34; /data/app/com.prashant.maps-2/base .apk&#34;],nativeLibraryDirectories = [/ vendor / lib,/ system / lib]] 02-28 19:56:58.052:E / AndroidRuntime(2857):at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 02-28 19:56:58.052:E / AndroidRuntime(2857):at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 02-28 19:56:58.052:E / AndroidRuntime(2857):at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 02-28 19:56:58.052:E / AndroidRuntime(2857):在android.app.Fragment.instantiate(Fragment.java:604) 02-28 19:56:58.052:E / AndroidRuntime(2857):......还有23个 02-28 19:56:58.052:E / AndroidRuntime(2857):抑制:java.lang.ClassNotFoundException:com.google.android.gms.maps.SupportMapFragment 02-28 19:56:58.052:E / AndroidRuntime(2857):at java.lang.Class.classForName(Native Method) 02-28 19:56:58.052:E / AndroidRuntime(2857):at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 02-28 19:56:58.052:E / AndroidRuntime(2857):at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 02-28 19:56:58.052:E / AndroidRuntime(2857):at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 02-28 19:56:58.052:E / AndroidRuntime(2857):......还有25个 02-28 19:56:58.052:E / AndroidRuntime(2857):引起:java.lang.NoClassDefFoundError:使用引导类加载器找不到类;没有可用的堆栈
答案 0 :(得分:0)
检查以下内容:
在AndroidManifest中提供Google Play服务版和您的API地图密钥。您似乎只拥有Google Play服务元数据(并以硬编码方式提供 - 并不好)
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_API_KEY"/>
</application>
在&#39; build.gradle&#39;中加入Google Play服务。你的申请。
...
dependencies {
compile 'com.google.android.gms:play-services:6.1.+'
}
如果您仍然遇到问题,请尝试更改&#39; android:name&#39;到了班级&#39;在片段标签中:
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>