我知道这个问题经常被报告,最简单、经常推荐的解决方案是检查我如何引用 google play 服务库。然而,我非常有信心我已经完成了所有的工作。我确实因为这个错误而失眠了,所以任何建议都值得赞赏。预先感谢。
首先,这是我的堆栈跟踪:
02-06 15:32:12.577: E/AndroidRuntime(17070): java.lang.RuntimeException: Unable to start activity ComponentInfo{raj.wifiapp/raj.wifiapp.MainActivity}: android.view.InflateException: Binary XML file line #29: Error inflating class fragment
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2438)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.ActivityThread.access$900(ActivityThread.java:168)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.os.Handler.dispatchMessage(Handler.java:102)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.os.Looper.loop(Looper.java:146)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.ActivityThread.main(ActivityThread.java:5678)
02-06 15:32:12.577: E/AndroidRuntime(17070): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 15:32:12.577: E/AndroidRuntime(17070): at java.lang.reflect.Method.invoke(Method.java:515)
02-06 15:32:12.577: E/AndroidRuntime(17070): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
02-06 15:32:12.577: E/AndroidRuntime(17070): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
02-06 15:32:12.577: E/AndroidRuntime(17070): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
02-06 15:32:12.577: E/AndroidRuntime(17070): at dalvik.system.NativeStart.main(Native Method)
02-06 15:32:12.577: E/AndroidRuntime(17070): Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class fragment
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
02-06 15:32:12.577: E/AndroidRuntime(17070): at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
02-06 15:32:12.577: E/AndroidRuntime(17070): at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:631)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.view.LayoutInflater.inflate(Native Method)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
02-06 15:32:12.577: E/AndroidRuntime(17070): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:350)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.Activity.setContentView(Activity.java:2063)
02-06 15:32:12.577: E/AndroidRuntime(17070): at raj.wifiapp.MainActivity.onCreate(MainActivity.java:58)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.Activity.performCreate(Activity.java:5586)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2402)
02-06 15:32:12.577: E/AndroidRuntime(17070): ... 12 more
02-06 15:32:12.577: E/AndroidRuntime(17070): 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
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.Fragment.instantiate(Fragment.java:597)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.Fragment.instantiate(Fragment.java:561)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.Activity.onCreateView(Activity.java:5111)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
02-06 15:32:12.577: E/AndroidRuntime(17070): ... 25 more
02-06 15:32:12.577: E/AndroidRuntime(17070): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/raj.wifiapp-8.apk"],nativeLibraryDirectories=[/data/app-lib/raj.wifiapp-8, /vendor/lib, /system/lib]]
02-06 15:32:12.577: E/AndroidRuntime(17070): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
02-06 15:32:12.577: E/AndroidRuntime(17070): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
02-06 15:32:12.577: E/AndroidRuntime(17070): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
02-06 15:32:12.577: E/AndroidRuntime(17070): at android.app.Fragment.instantiate(Fragment.java:583)
02-06 15:32:12.577: E/AndroidRuntime(17070): ... 28 more
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="raj.wifiapp"
android:versionCode="1"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="raj.wifiapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="raj.wifiapp.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" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<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="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAaizOmaOj15uOjUmNA4OnowrOLv88_vKI" />
<activity
android:name="raj.wifiapp.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="raj.wifiapp.Tracker">
<category android:name="android.intent.category.Default" />
</activity>
</application>
</manifest>
这是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="14dp"
android:text="Switch views" />
<Button
android:id="@+id/btn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="17dp"
android:text="Scan" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
发生错误是因为您尚未在应用程序项目中添加 Google Play 服务库。请按照以下教程在您的应用程序中添加Google Play服务以获取Google地图。