Google Map和ViewPagers出错

时间:2014-05-26 15:57:30

标签: android android-viewpager maps fragment

我有一个ViewPager,其中一个Fragment是一个ListView,另一个是地图,当我尝试添加地图应用程序崩溃时,我尝试使用支持库而没有..不起作用所以我会把错误日志,如果有人知道thnks




    05-26 16:21:50.595: E/AndroidRuntime(13463): FATAL EXCEPTION: main
    05-26 16:21:50.595: E/AndroidRuntime(13463): Process: com.infosports.actividadesdeportivasb, PID: 13463
    05-26 16:21:50.595: E/AndroidRuntime(13463): java.lang.NullPointerException
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at com.infosports.fracss.FracMap.onCreateView(FracMap.java:24)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.View.measure(View.java:16537)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5135)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.View.measure(View.java:16537)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1226)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.widget.ScrollView.onMeasure(ScrollView.java:326)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.View.measure(View.java:16537)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5135)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.View.measure(View.java:16537)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5135)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.View.measure(View.java:16537)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5135)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.View.measure(View.java:16537)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1947)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1137)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1326)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1024)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5796)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.Choreographer.doFrame(Choreographer.java:544)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.os.Handler.handleCallback(Handler.java:733)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.os.Handler.dispatchMessage(Handler.java:95)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.os.Looper.loop(Looper.java:136)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at android.app.ActivityThread.main(ActivityThread.java:5102)
    05-26 16:21:50.595: E/AndroidRunleme istime(13463):     at java.lang.reflect.Method.invokeNative(Native Method)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at java.lang.reflect.Method.invoke(Method.java:515)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    05-26 16:21:50.595: E/AndroidRuntime(13463):    at dalvik.system.NativeStart.main(Native Method)

我想这个问题在课堂上

public class FracMap extends Fragment {
        View rootView;
       MapFragment mapView;
       // GoogleMap map;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

        rootView=inflater.inflate(R.layout.frac_maps, container, false);
        GoogleMap mapa = ((MapFragment) getActivity().getFragmentManager()
                .findFragmentById(R.id.map)).getMap();
        return rootView;

    }

    public static FracMap map(){

        return new FracMap();
    }
}

manifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.infosports.actividadesdeportivasb"
    android:versionCode="1"
    android:versionName="1.0">
<permission 
android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" 
android:protectionLevel="signature"></permission>
<uses-permission 
android:name="com.infosports.actividadesdeportivasb"/>

    <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-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />
    <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
     <application
        android:allowBackup="true"
        android:icon="@drawable/path3190"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="got this"/>
        <meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />


          <uses-library android:name="com.google.android.maps" />
        <activity
            android:name="com.infosports.actividadesdeportivasb.MainActivity"
            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:configChanges="orientation|screenSize"
              android:name="com.infosports.actividadesdeportivasb.SelectedActivity"
            android:label="@string/app_name" >
    </activity>

         <activity
              android:name="com.infosports.actividadesdeportivasb.InfoNews"
            android:label="@string/app_name" >
    </activity>
    </application>

</manifest>

布局

<?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"/>

1 个答案:

答案 0 :(得分:0)

在布局中使用此特定SupportMapFragment类时,您必须按如下方式处理getSupportMapFragment()方法:

GoogleMap mapa = ((SupportMapFragment) getActivity().getSupportFragmentManager()
            .findFragmentById(R.id.map)).getMap();  

如果有帮助,请告诉我。