错误膨胀类片段,android map v2

时间:2014-10-17 09:01:47

标签: android google-maps android-fragments

这个问题已经被问过很多次了,我已经尝试了几乎所有解决方案,但在我的案例中没有任何效果。这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>

这是我的java代码

public class Storesearch extends FragmentActivity{
  private GoogleMap map; 
  private LocationManager locationManager;
  private Location mylocation;
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_storesearch);
    determineLocation();
  }

  protected void onStart() {
       super.onStart();
       setupMap();
       appMapSettings();
       spotCurrentLocation(mylocation);
  }

  public void setupMap(){
   if(map==null){
     SupportMapFragment mf=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);   
      map=mf.getMap();

   }

  }

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fyp.searchstore"
    android:versionCode="1"
    android:versionName="1.0" >
    <permission
        android:name="com.fyp.searchstore.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.fyp.searchstore.permission.MAPS_RECEIVE" />


    <meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API KEY"/>

     <meta-data
            android:name="com.google.android.gms.version"
            android:value="19" />

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

     <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"/>
<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=".Storesearch"
            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报告

10-17 04:45:12.664: D/AndroidRuntime(2461): Shutting down VM
10-17 04:45:12.664: W/dalvikvm(2461): threadid=1: thread exiting with uncaught exception (group=0xb2ad1ba8)
10-17 04:45:12.684: E/AndroidRuntime(2461): FATAL EXCEPTION: main
10-17 04:45:12.684: E/AndroidRuntime(2461): Process: com.fyp.searchstore, PID: 2461
10-17 04:45:12.684: E/AndroidRuntime(2461): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fyp.searchstore/com.fyp.searchstore.Storesearch}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
10-17 04:45:12.684: E/AndroidRuntime(2461):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at android.os.Handler.dispatchMessage(Handler.java:102)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at android.os.Looper.loop(Looper.java:136)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at android.app.ActivityThread.main(ActivityThread.java:5017)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at java.lang.reflect.Method.invokeNative(Native Method)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at java.lang.reflect.Method.invoke(Method.java:515)
10-17 04:45:12.684: E/AndroidRuntime(2461):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)

它给我第二行xml文件的错误。我使用版本20的谷歌播放服务,而我的Android API是版本19.我遇到的问题是由于这些版本?提前致谢

2 个答案:

答案 0 :(得分:0)

看起来这个人遇到了与你相同的问题:Stackoverflow
看第二个答案。您是否复制了 .jar 文件,或者是否将其添加为引用库?

您下载了Android支持库吗?

答案 1 :(得分:0)

你好,你试图在Android模拟器上检查它吗?如果是,请使用google-api模拟器,其中将包含支持库。尝试检查真正的Android设备,如果它仍然给你相同的错误,而不是在你的项目中添加谷歌播放服务。