这是我如何在FrameLayout中动态添加地图。
new Handler().postDelayed(() -> {
if (isAdded()) {
new Thread(() -> {
try {
SupportMapFragment mf = SupportMapFragment.newInstance();
getChildFragmentManager().beginTransaction()
.replace(R.id.view_map, mf)
.commit();
mActivity.runOnUiThread(() -> mf.getMapAsync(this));
} catch (Exception ignored) {}
}).start();
}
}, 100);
它工作正常,但在某些情况下,应用程序崩溃了Resources$NotFoundException
。这是崩溃日志。
android.content.res.Resources$NotFoundException: Resource ID #0x7f07000f
at android.content.res.Resources.getValue(Resources.java: 1266)
at android.content.res.Resources.getDimensionPixelSize(Resources.java: 673)
at maps.ad.ay. < init > (Unknown Source)
at maps.ad.ay. < init > (Unknown Source)
at maps.ad.t.a(Unknown Source)
at maps.ad.M.a(Unknown Source)
at wd.onTransact(: com.google.android.gms.DynamiteModulesB: 107)
at android.os.Binder.transact(Binder.java: 380)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$zza.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.zza$4.zzb(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at android.support.v4.app.Fragment.performCreateView(Fragment.java: 2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1290)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java: 801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java: 1677)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java: 536)
at android.os.Handler.handleCallback(Handler.java: 746)
at android.os.Handler.dispatchMessage(Handler.java: 95)
at android.os.Looper.loop(Looper.java: 135)
at android.app.ActivityThread.main(ActivityThread.java: 5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java: 372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 702)