在没有位图的情况下向地图添加标记会导致异常

时间:2017-11-03 02:38:43

标签: android google-maps

在没有位图的情况下向地图添加标记会导致异常,但我无法捕获异常。

确定问题很容易解决,只需添加适当的位图,但在没有应用程序崩溃的情况下捕获异常会很棒。

private void showLocations() {

    for(Map location : locations) {
        MarkerOptions markerOptions = makeMarkerOptions(location);

        if(googleMap != null && markerOptions != null) {
            Marker marker = googleMap.addMarker(markerOptions);
            markers.put(marker, location);
        }
    }
}

异常以addmarker()

的形式出现
11-03 10:26:29.297 13148-13148/au.com.gaiaresources.microblitzbeta E/AndroidRuntime: FATAL EXCEPTION: main
    Process: au.com.zzzzzzz.zzzzzzzz, PID: 13148
    com.google.maps.api.android.lib6.common.apiexception.b: Failed to decode image. The provided image must be a Bitmap.
        at com.google.maps.api.android.lib6.impl.g.a(:com.google.android.gms.DynamiteModulesB@11744448:9)
        at com.google.maps.api.android.lib6.impl.n.a(:com.google.android.gms.DynamiteModulesB@11744448:7)
        at com.google.maps.api.android.lib6.impl.cz.<init>(:com.google.android.gms.DynamiteModulesB@11744448:25)
        at com.google.maps.api.android.lib6.impl.ba.a(:com.google.android.gms.DynamiteModulesB@11744448:487)
        at com.google.android.gms.maps.internal.k.onTransact(:com.google.android.gms.DynamiteModulesB@11744448:94)
        at android.os.Binder.transact(Binder.java:507)
        at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)

如何捕获此异常?我尝试捕获com.google.maps.api.android.lib6.common.apiexception.b但它不存在?

private void showLocations() {

    for(Map location : locations) {
        try {
            MarkerOptions markerOptions = makeMarkerOptions(location);

            if(googleMap != null && markerOptions != null) {
                Marker marker = googleMap.addMarker(markerOptions);
                markers.put(marker, location);
            }
        } catch(com.google.maps.api.android.lib6.common.apiexception.b ex) {
            getDependencyService().getLogger().error(ex.getLocalizedMessage());
        }
    }
}

1 个答案:

答案 0 :(得分:-1)

试试这个:

try {
        //Your code
    } catch(Throwable t) {
        getDependencyService().getLogger().error(t.getLocalizedMessage());
    }