0
我在此函數中收到此錯誤,並且不知道如何解決該問題。 「潛在的空指針訪問:變量流可能在這個位置空」 下面是代碼:潛在的空指針訪問:變量流在此位置可能爲空
public void downloadAudioIncrement(String mediaUrl) throws IOException {
/*URLConnection cn = new URL(mediaUrl).openConnection(Proxy.NO_PROXY);
cn.connect();
InputStream stream = cn.getInputStream();*/
URL url = new URL(mediaUrl);
InputStream stream = url.openStream();
//Toast.makeText(this.context, "here3", Toast.LENGTH_LONG);
if (stream == null) {
Log.e(getClass().getName(), "Não é possível criar InputStream para a url: " + mediaUrl);
}
//downloadingMediaFile = new File(context.getCacheDir(),"downloadingMedia_" + (counter++) + ".dat");
downloadingMediaFile = new File(context.getCacheDir(),"downloadingMedia_.dat");
FileOutputStream out = new FileOutputStream(downloadingMediaFile);
byte buf[] = new byte[16384];
int totalBytesRead = 0, incrementalBytesRead = 0;
do {
int numread = ***stream***.read(buf);
if (numread <= 0)
break;
out.write(buf, 0, numread);
totalBytesRead += numread;
incrementalBytesRead += numread;
totalKbRead = totalBytesRead/1000;
testMediaBuffer();
fireDataLoadUpdate();
} while (validateNotInterrupted());
if (validateNotInterrupted()) {
fireDataFullyLoaded();
//testMediaBuffer();
//fireDataLoadUpdate();
}
***stream***.close();
out.close();
}
如何解決這個問題?這裏出現的錯誤:
numread ***stream***.Read = int (buf);
這裏:
***stream***.Close();
完美的,它現在工作。 – 2013-02-25 19:05:09