Android地图,错误膨胀片段

时间:2014-02-26 18:06:24

标签: java android android-fragments android-maps-v2

我正在尝试在我的Android应用程序上使用谷歌地图,但我仍然有这个错误:errror膨胀类片段。 我按照官方谷歌开发者指南没有得到好结果,当我开始活动时,我的应用程序仍然崩溃。

我的活动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 个答案:

答案 0 :(得分:0)

MapFragment替换为XML文件中的SupportMapFragment,并检查它是否有效并告诉我。