首页 > 解决方案 > 为什么应用程序仅在我应用更改时因为缺少维度(对于谷歌地图)而崩溃?

问题描述

我的应用程序仅在我应用更改时(而不是在我运行应用程序时)崩溃,并且在我加载谷歌地图的片段中失败。给出的错误如下:

Process: com.locatecars.findspot, PID: 20722
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.locatecars.findspot/com.locatecars.findspot.MainActivity}: android.content.res.Resources$NotFoundException: Resource "com.locatecars.findspot:dimen/card_icon_multiline_padding_bottom" (7f060059) is not a Drawable (color or path): TypedValue{t=0x5/d=0xc30c21 a=3 r=0x7f060059}

这个错误指向我的方法是:

private void initGoogleMap(Bundle savedInstanceState) {
        Bundle mapViewBundle = null;
        if (savedInstanceState != null) {
            mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY);
        }
        mapView.onCreate(mapViewBundle); //<-- this line in particular
        mapView.getMapAsync(this);

        if (geoApiContext == null) {
            geoApiContext = new GeoApiContext.Builder().apiKey(getString(R.string.google_api_key)).build();
        }
    }

编辑 这是克里斯建议后的片段

Bundle mapViewBundle = savedInstanceState != null ?
                savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY) : new Bundle();
        savedInstanceState.putBundle(MAPVIEW_BUNDLE_KEY, mapViewBundle);
        mapView.onSaveInstanceState(mapViewBundle);

编辑 2

在再次考虑了克里斯的回答之后,这就是有效的:

Bundle mapViewBundle = savedInstanceState != null ?
                savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY) : new Bundle();
        mapView.onSaveInstanceState(mapViewBundle);

标签: androidgoogle-maps

解决方案


看起来您正在传递一个空包。尝试这样的事情:

Bundle mapViewBundle = savedInstanceState != null ? 
  savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY) : new Bundle();

推荐阅读