我正在尝试使用httpurlconnection从fb下载头像。这在android上运行良好。如果我从非SSL服务器下载任意图像,它也适用于带有robovm的iOS。如果我尝试在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块中运行此代码,代码在connect()之后立即跳到最后(我断开连接)。它抛出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)
答案 0 :(得分:0)
完全重新安装roboVM插件后,此问题已得到解决。我不知道真正的问题是什么。