gpt4 book ai didi

android - 发布了未知的位图引用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:07 25 4
gpt4 key购买 nike

我正在尝试在 Google map v2 中设置标记图标。我正在通过网络下载一些图像并在代码中更改它们的背景。之后我将它们设置为标记的图标。第一次创建 map 时它工作正常,但旋转后出现异常。

我运行它的 Android 版本:4.3

我的代码如下:

        UrlImageViewHelper.loadUrlDrawable(TuvaletlerMapActivity.this,
iconUrl, new UrlImageViewCallback() {

@Override
public void onLoaded(ImageView iv, Bitmap bm,
String arg2, boolean arg3) {
Bitmap bitmap = VenuesHelper.iconizeBitmap(bm);
marker.setIcon(BitmapDescriptorFactory
.fromBitmap(bitmap));
}
});

VenuesHelper.iconizeBitmap()如下:

public static Bitmap iconizeBitmap(Bitmap bm) {
Bitmap bitmap = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(),
bm.getConfig());
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.parseColor("#33B5E5"));
canvas.drawBitmap(bm, 0, 0, null);
return bitmap;
}

堆栈轨迹如下:

08-07 10:16:50.684: E/AndroidRuntime(19001): FATAL EXCEPTION: main
08-07 10:16:50.684: E/AndroidRuntime(19001): java.lang.IllegalArgumentException: Released unknown bitmap reference
08-07 10:16:50.684: E/AndroidRuntime(19001): at maps.as.i.a(Unknown Source)
08-07 10:16:50.684: E/AndroidRuntime(19001): at maps.ah.o.b(Unknown Source)
08-07 10:16:50.684: E/AndroidRuntime(19001): at maps.ah.bn.a(Unknown Source)
08-07 10:16:50.684: E/AndroidRuntime(19001): at bix.onTransact(SourceFile:204)
08-07 10:16:50.684: E/AndroidRuntime(19001): at android.os.Binder.transact(Binder.java:347)
08-07 10:16:50.684: E/AndroidRuntime(19001): at com.google.android.gms.internal.dm$a$a.f(Unknown Source)
08-07 10:16:50.684: E/AndroidRuntime(19001): at com.google.android.gms.maps.model.Marker.setIcon(Unknown Source)
08-07 10:16:50.684: E/AndroidRuntime(19001): at com.behlul.tuvaletbul.TuvaletlerMapActivity$TuvaletliYukleCallbacks$1.onLoaded(TuvaletlerMapActivity.java:250)
08-07 10:16:50.684: E/AndroidRuntime(19001): at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$2.run(UrlImageViewHelper.java:615)
08-07 10:16:50.684: E/AndroidRuntime(19001): at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$3.onPostExecute(UrlImageViewHelper.java:653)
08-07 10:16:50.684: E/AndroidRuntime(19001): at com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$3.onPostExecute(UrlImageViewHelper.java:1)
08-07 10:16:50.684: E/AndroidRuntime(19001): at android.os.AsyncTask.finish(AsyncTask.java:631)
08-07 10:16:50.684: E/AndroidRuntime(19001): at android.os.AsyncTask.access$600(AsyncTask.java:177)
08-07 10:16:50.684: E/AndroidRuntime(19001): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
08-07 10:16:50.684: E/AndroidRuntime(19001): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 10:16:50.684: E/AndroidRuntime(19001): at android.os.Looper.loop(Looper.java:137)
08-07 10:16:50.684: E/AndroidRuntime(19001): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-07 10:16:50.684: E/AndroidRuntime(19001): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 10:16:50.684: E/AndroidRuntime(19001): at java.lang.reflect.Method.invoke(Method.java:525)
08-07 10:16:50.684: E/AndroidRuntime(19001): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-07 10:16:50.684: E/AndroidRuntime(19001): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-07 10:16:50.684: E/AndroidRuntime(19001): at dalvik.system.NativeStart.main(Native Method)

最佳答案

我遇到了类似的问题,当我尝试重新加载执行“myMarker.setIcon()”的标记时,然后在一些刷新之后应用程序遇到“java.lang.IllegalArgumentException:发布了未知位图引用”。

我发现调用“myMap.clear()”来清除所有标记是个问题,实际上在函数文档中您可以阅读“从 map 中删除所有标记、折线、多边形、叠加层等”。

好吧,“etc”似乎比我预期的要好......

为了解决这个问题,我使用了一个自定义函数来遍历保存在 HashMap 中的所有标记并一个一个地删除,仅此而已,我的代码中不再有类似的异常。

您可以遍历所有标记以删除它们,如下所示:

/**
* Alternative to myMap.clear() to avoid undesired exceptions
*/
private void clearAllMapMarkers() {
// Clearing the current map markers being shown
// Note that we do not use myMap.clear() because that incur in the exception
// "java.lang.IllegalArgumentException: Released unknown bitmap reference"
try {
for (Map.Entry<String, Marker> markerEntry : mMarkerList.entrySet()) {
markerEntry.getValue().remove();
}
} catch (IllegalArgumentException e) {
// Manage here the exception (never raised but who knows...)
}
}

关于android - 发布了未知的位图引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18097090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com