我希望应用程序在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()
}
}
怎么做才能得到例外?