Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android无法实例化片段Google map api 2_Android_Google Maps_Android Fragments_Google Maps Api 2_Android Support Library - Fatal编程技术网

android无法实例化片段Google map api 2

android无法实例化片段Google map api 2,android,google-maps,android-fragments,google-maps-api-2,android-support-library,Android,Google Maps,Android Fragments,Google Maps Api 2,Android Support Library,这些是我的代码,我正在为android api 8+编程。我想在地图上显示位置,我正在使用GoogleMapAPI2,我导入了google-play-services_lib,jar文件退出。我有一个滑动标签,它包含3个片段。这是我的密码 swipe tab Layout <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.

这些是我的代码,我正在为android api 8+编程。我想在地图上显示位置,我正在使用GoogleMapAPI2,我导入了google-play-services_lib,jar文件退出。我有一个滑动标签,它包含3个片段。这是我的密码

swipe tab Layout 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Spots_tab2"
android:background="#cccc00"
 >
<fragment 
    android:id="@+id/map"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:name="com.google.android.gsm.maps.SupportMapFragment"
    />
舱单:

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <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" />

    <permission
    android:name="com.example.maps.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

   <uses-permission android:name="com.example.maps.permission.MAPS_RECEIVE" />

   <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/Theme.AppCompat.Light" >
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAWOjtGwFaWIL4JQqJfrpwoxS1Mx7oMDsk" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    </application>
另外,这就是我导入google play服务的方式,我将google play服务作为项目导入到我的工作区中,然后将其作为库添加到我的项目中

你能帮帮我吗
谢谢

请尝试此代码。这个代码在我这边起作用

 map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
并将此代码用于布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:enabled="true" />

</RelativeLayout>


可能重复-将所有代码从
onActivityCreted()
移动到
onCreateView(…)
和tryUse class=“com.google.android.gms.maps.MapFragment”而不是SupportMapFragment,应该可以工作;)@SimplePlan onCreateView for fragment不是一个好的领域,因为可能活动还没有加载,还有一些其他问题,事实上,android不允许我将这些代码放进去there@AdrienCerdan,你能告诉我一个例子吗,我试着把代码放进去并替换它,但它给出了错误。是的,它适用于android api11+,正如我所说,我想在api8+上运行它。我有一个类似于api 11的代码,它工作得很好。我也有同样的问题。由于某些原因,这不适用于较旧的API。我继续得到空指针异常
 map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:enabled="true" />

</RelativeLayout>