1
@Override
public void run() {
URL imgurl;
int Read;
try {
imgurl = new URL(ServerUrl);
HttpURLConnection conn = (HttpURLConnection) imgurl.openConnection();
int len = conn.getContentLength();
Log.d("check", "ContentLength:" + len);
Log.d("check", "ServerUrl:" + ServerUrl);
Log.d("check", "LocalPath:" + LocalPath);
byte[] tmpByte = new byte[len];
InputStream is = conn.getInputStream();
File file = new File(LocalPath);
FileOutputStream fos = new FileOutputStream(file);
for (;;) {
Read = is.read(tmpByte);
if (Read <= 0) {
break;
}
fos.write(tmpByte, 0, Read);
}
is.close();
fos.flush();
fos.close();
conn.disconnect();
} catch (MalformedURLException e) {
ut.CalltoAlertDialog_ok(getString(R.string.alert), getString(R.string.setting_skin_downloadfail));
} catch (IOException e) {
ut.CalltoAlertDialog_ok(getString(R.string.alert), getString(R.string.setting_skin_downloadfail));
}
mAfterDown.sendEmptyMessage(0);
}
這是文件下載源。我的文件下載器突然出現錯誤
此代碼打印錯誤 「NegativeArraySizeException」 從這裏
byte[] tmpByte = new byte[len];
所以,我檢查LEN的值。
len的值是-1。
但是.. 當我昨天創建,此代碼不是打印錯誤。我有2個apk文件。我有2個apk文件。我有2個共享文件對話框。
昨天創建的apk不是問題。即使現在這個apk也沒問題。
但是,今天創建的apk是問題。
我沒有修改任何東西。
這是什麼原因?
變量應該用小寫字母開頭。否則混淆。 –
如果代碼工作(代碼相同),那麼你的問題似乎是在服務器端。 – Merlevede