Android GoogleMap:将getFragmentManager()更改为SupportMapFragment() - NullPointerException

时间:2014-03-04 10:06:40

标签: android android-fragments google-maps-android-api-2

我希望应用程序在Android-8

版本上运行

我找到了一些“答案”,但仍然在NullPointerException上收到。

        try {   
            FragmentManager myFM = ActivityMapa.this.getSupportFragmentManager();

            final SupportMapFragment myMAPF = (SupportMapFragment) myFM.findFragmentById(R.id.mapa);
            map = myMAPF.getMap();
        } catch (Exception e) {
            Log.d("mapa", "FR error: " + e);
            map = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapa)).getMap();
        }

第二个答案:

// in try()
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapa)).getMap();

代码在:

public class ActivityMap extends ActivityOptions {  // ActivityOptions extends FragmentActivity

    (...)
    protected void onCreate() {

        // try()

    }


}

怎么做才能得到例外?

0 个答案:

没有答案