Here is the log:
03-28 19:12:29.083: E/AndroidRuntime(22004): FATAL EXCEPTION: AsyncTask #5
03-28 19:12:29.083: E/AndroidRuntime(22004): java.lang.RuntimeException: An error occured while executing doInBackground()
03-28 19:12:29.083: E/AndroidRuntime(22004): at android.os.AsyncTask$3.done(AsyncTask.java:278)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.lang.Thread.run(Thread.java:856)
03-28 19:12:29.083: E/AndroidRuntime(22004): Caused by: java.lang.OutOfMemoryError
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.lang.String.<init>(String.java:364)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.lang.String.<init>(String.java:223)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.io.ByteArrayOutputStream.toString(ByteArrayOutputStream.java:175)
03-28 19:12:29.083: E/AndroidRuntime(22004): at com.vtube.data.YoutubeAPI.doGetRequest(YoutubeAPI.java:71)
03-28 19:12:29.083: E/AndroidRuntime(22004): at com.vtube.data.YoutubeAPI.getPopular(YoutubeAPI.java:86)
03-28 19:12:29.083: E/AndroidRuntime(22004): at com.vtube.data.YoutubeAPI.getPopularEntry(YoutubeAPI.java:97)
03-28 19:12:29.083: E/AndroidRuntime(22004): at com.vtube.app.BaseFourActivity$PageZeroRefreshTask.doInBackground(BaseFourActivity.java:358)
03-28 19:12:29.083: E/AndroidRuntime(22004): at com.vtube.app.BaseFourActivity$PageZeroRefreshTask.doInBackground(BaseFourActivity.java:1)
03-28 19:12:29.083: E/AndroidRuntime(22004): at android.os.AsyncTask$2.call(AsyncTask.java:264)
03-28 19:12:29.083: E/AndroidRuntime(22004): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-28 19:12:29.083: E/AndroidRuntime(22004): ... 4 more
I don't understand why this go wrong, this app not crash often, only in a few times. This happens when I leave the app for a while. where the code went wrong:
public static String doGetRequest(String url) throws IOException{
HttpClient lClient = new DefaultHttpClient();
HttpGet lGetMethod = new HttpGet(url);
HttpResponse lResp = null;
try {
lResp = lClient.execute(lGetMethod);
} catch (ClientProtocolException e1) {
Log.v(TAG, e1.toString());
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
ByteArrayOutputStream lBOS = new ByteArrayOutputStream();
String lInfoStr = "";
if (lResp != null){
try {
lResp.getEntity().writeTo(lBOS);
lInfoStr = lBOS.toString("UTF-8");
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return lInfoStr;
}
lInfoStr = lBOS.toString("UTF-8");
this paticular line
How can I solve this? Does toString()
cost a lot of memory?