我一直收到这个错误提示?
07-25 17:04:00.796: ERROR/AndroidRuntime(420): Caused by: java.lang.OutOfMemoryError
07-25 17:04:00.796: ERROR/AndroidRuntime(420): at org.apache.http.impl.io.AbstractSessionInputBuffer.init(AbstractSessionInputBuffer.java:79)
07-25 17:04:00.796: ERROR/AndroidRuntime(420): at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)
每次我尝试运行这个方法:
public void getImages() throws IOException{
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet("https://sites.google.com/site/theitrangers/images/webImages.txt");
HttpResponse response;
response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
InputStream is = buf.getContent();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line + "\n");
imageUrl = total.toString();
Log.v("getImage1", "Retreived image");
}
}
这个方法所做的就是从托管在网站上的文本文件中检索URL。
编辑:调试指向我的代码行。当它运行时,我会得到内存不足的错误。
public void getImages() throws IOException{
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet("https://sites.google.com/site/theitrangers/images/webImages.txt");
HttpResponse response;
**Specifically here:** response = httpclient.execute(httppost);
VM
不会对你有任何偏见。你之所以遇到 OOM 是因为你的程序可能已经耗尽了内存。:-P - Mukul Goel