2014-02-26 69 views
0

我想在我的Android應用程序上使用谷歌地圖,但我仍然有這個錯誤:errror膨脹類片段。 我按照官方的谷歌開發者指南沒有好的結果,我的應用程序仍然崩潰時,我開始的活動。Android地圖,錯誤充氣片段

我的活動XML代碼:

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/map" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:name="com.google.android.gms.maps.SupportMapFragment"/> 

這裏是我的清單XML文件:

<uses-sdk 
     android:minSdkVersion="11" 
     android:targetSdkVersion="19" /> 

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> 
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> 
<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_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" >   
     <activity 
      android:name="com.detector.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> 
     <activity 
     android:name="com.detector.ScannerWifi" 
     android:label="@string/app_name">   
    </activity> 
    <activity 
     android:name="com.detector.WifiMap" 
     android:label="@string/app_name">   
    </activity> 
    <meta-data 
    android:name="com.google.android.maps.v2.API_KEY" 
    android:value="MY API KEY HERE"/> 

    </application> 

</manifest> 

我的Java代碼:

public class WifiMap extends FragmentActivity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.wifi_map); 

    } 
} 

logcat的

02-26 19:10:30.413: E/AndroidRuntime(27614): FATAL EXCEPTION: main 
02-26 19:10:30.413: E/AndroidRuntime(27614): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.detector/com.detector.WifiMap}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.ActivityThread.access$600(ActivityThread.java:139) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.os.Handler.dispatchMessage(Handler.java:99) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.os.Looper.loop(Looper.java:156) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.ActivityThread.main(ActivityThread.java:4987) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at java.lang.reflect.Method.invokeNative(Native Method) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at java.lang.reflect.Method.invoke(Method.java:511) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at dalvik.system.NativeStart.main(Native Method) 
02-26 19:10:30.413: E/AndroidRuntime(27614): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.Activity.setContentView(Activity.java:1892) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at com.detector.WifiMap.onCreate(WifiMap.java:15) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.Activity.performCreate(Activity.java:4538) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161) 
02-26 19:10:30.413: E/AndroidRuntime(27614): ... 11 more 
02-26 19:10:30.413: E/AndroidRuntime(27614): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.Fragment.instantiate(Fragment.java:612) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.Fragment.instantiate(Fragment.java:572) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.Activity.onCreateView(Activity.java:4303) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673) 
02-26 19:10:30.413: E/AndroidRuntime(27614): ... 20 more 
02-26 19:10:30.413: E/AndroidRuntime(27614): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment 
02-26 19:10:30.413: E/AndroidRuntime(27614): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
02-26 19:10:30.413: E/AndroidRuntime(27614): at android.app.Fragment.instantiate(Fragment.java:594) 
02-26 19:10:30.413: E/AndroidRuntime(27614): ... 23 more 
+1

張貼您的logcat請 –

回答

0

用你的XML文件替換MapFragmentSupportMapFragment,檢查它是否正常工作並告訴我。

+0

相同的結果..同樣的錯誤 – user3357127

+0

請參閱此答案爲classNotFoundException http://stackoverflow.com/questions/16572020/error-java-lang-classnotfoundexception-com-google-android-gms-地圖 - mapfragment –