gpt4 book ai didi

java - Robovm 无法通过 https 下载图像

转载 作者:太空宇宙 更新时间:2023-11-04 14:11:33 26 4
gpt4 key购买 nike

我正在尝试使用 httpurlconnection 从 Facebook 下载头像图像。这在安卓上运行良好。如果我从非 SSL 服务器下载任意图像,它也可以在 iOS 上使用 robovm 运行。如果我尝试在 iOS 上下载 Facebook 头像,几乎每次都会失败。有时它确实有效(似乎是随机的)。我应该对 iOS 使用不同的方法吗?

我使用以下代码下载我的图像(在单独的线程中)

HttpURLConnection conn= (HttpURLConnection)url.openConnection(); 
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
if(length<=0) return null;
InputStream is = conn.getInputStream();
DataInputStream dis = new DataInputStream(is);
byte[] data = new byte[length];
dis.readFully(data);
Pixmap pixmap = new Pixmap(data, 0, data.length);

我在 try/catch/finally block 中运行此代码,代码在 connect() 之后立即跳到finally(我断开连接的地方)。它抛出一个 IllegalMonitorStateException。

java.lang.IllegalMonitorStateException: unlock of unowned monitor
java.lang.IllegalMonitorStateException: unlock of unowned monitor
at com.android.okhttp.Connection.upgradeToTls(Connection.java)
at com.android.okhttp.Connection.connect(Connection.java)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java)
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java)
at bla.helpers.ImageManager.syncDownloadPixmapFromURL(ImageManager.java)
at bla.helpers.ImageManager.access$1(ImageManager.java)
at bla.helpers.ImageManager$2.run(ImageManager.java)
at java.lang.Thread.run(Thread.java)
at com.android.okhttp.Connection.upgradeToTls(Connection.java)
at com.android.okhttp.Connection.connect(Connection.java)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java)
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java)
at bla.helpers.ImageManager.syncDownloadPixmapFromURL(ImageManager.java)
at bla.helpers.ImageManager.access$1(ImageManager.java)
at bla.helpers.ImageManager$2.run(ImageManager.java)
at java.lang.Thread.run(Thread.java)

最佳答案

完全重新安装 roboVM 插件后,此问题已得到解决。我不知道真正的问题是什么。

关于java - Robovm 无法通过 https 下载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28264920/

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