以下是我從服務器獲取XML的代碼,但是當XML很大時,出現內存不足錯誤您能否告訴我需要更改我的代碼大xml存在時出現內存不足錯誤
@Override
protected String doInBackground(String... arg0) {
String result = "";
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(getString(R.string.requesturl));
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget);
// Get hold of the response entity
HttpEntity entity = response.getEntity();
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
result = EntityUtils.toString(response.getEntity());
}
} catch (Exception e) {
}
return result;
}
@Override
protected void onPostExecute(String result)
{
progressDialog.dismiss();
ParseResponse parse=new ParseResponse();
InputSource is = new InputSource(new StringReader(result));
Gesmes gesmes=parse.parseXML(is);
}
這似乎很好地工作時,XML是小 這裏是我的logcat:
03-31 15:01:25.547: E/AndroidRuntime(9791): java.lang.OutOfMemoryError
03-31 15:01:25.547: E/AndroidRuntime(9791): at java.util.ArrayList.add(ArrayList.java:118)
03-31 15:01:25.547: E/AndroidRuntime(9791): at com.parser.ParseResponse.parseXML(ParseResponse.java:64)
03-31 15:01:25.547: E/AndroidRuntime(9791): at com.europeanexchangerates.MainActivity$AsyncCurrency.onPostExecute(MainActivity.java:426)
03-31 15:01:25.547: E/AndroidRuntime(9791): at com.europeanexchangerates.MainActivity$AsyncCurrency.onPostExecute(MainActivity.java:1)
03-31 15:01:25.547: E/AndroidRuntime(9791): at android.os.AsyncTask.finish(AsyncTask.java:632)
03-31 15:01:25.547: E/AndroidRuntime(9791): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-31 15:01:25.547: E/AndroidRuntime(9791): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
03-31 15:01:25.547: E/AndroidRuntime(9791): at android.os.Handler.dispatchMessage(Handler.java:102)
03-31 15:01:25.547: E/AndroidRuntime(9791): at android.os.Looper.loop(Looper.java:136)
03-31 15:01:25.547: E/AndroidRuntime(9791): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-31 15:01:25.547: E/AndroidRuntime(9791): at java.lang.reflect.Method.invokeNative(Native Method)
03-31 15:01:25.547: E/AndroidRuntime(9791): at java.lang.reflect.Method.invoke(Method.java:515)
03-31 15:01:25.547: E/AndroidRuntime(9791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-31 15:01:25.547: E/AndroidRuntime(9791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
請發表您的logcat –