2014-10-17 100 views
2

这个问题已被问了很多次,我已经尝试了几乎所有的解决方案,但没有任何工作在我的情况。这是我的XML错误膨胀类的片段,安卓地图v2

<?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文件的第二行。我使用谷歌播放服务的revision20,而我的Android API是版本19.我遇到的问题是由于这些版本?在此先感谢

+0

试一下这行代码:android:name =“com.google.android.gms.maps.SupportMapFragment”而不是“class”属性。 – 2014-10-17 09:07:18

+0

@pratik我试过这个,但没有工作:( – 2014-10-17 09:27:20

+0

Shifa,你在模拟器或设备上测试它吗? – 2014-10-17 09:28:05

回答

0

看起来像这家伙有同样的问题比你:Stackoverflow
看第二个答案。您是否复制了.jar文件,或者您是否将其添加为引用的库?

并且您是否下载了Android支持库?

0

你好,你想检查它在Android模拟器?如果是,请使用google-api模拟器,该模拟器中会有支持库。尝试检查真正的Android设备,如果它仍然给你同样的错误,而不是在你的项目中添加谷歌播放服务。

+0

YES m在google API emuator上测试它,并且在我的项目中添加了google播放服务,但如果您有真正的android设备,则仍然存在问题 – 2014-10-17 09:35:33

+0

,而不是尝试对此进行测试。它肯定会在那上面运行。我也有同样的问题,当我在设备上运行它比给我地图。当我试图在模拟器中运行时,它会给我膨胀类错误。 – 2014-10-17 11:22:06