我發現了一個代碼,但有時也有錯誤:在這條線java.lang.OutOfMemoryError如何解決這一問題
strHeaders.append(c);
請任何一個
StringBuilder strHeaders = new StringBuilder();
char c;
while ((c = (char)stream.read()) != -1) {
strHeaders.append(c);
if (strHeaders.length() > 5 && (strHeaders.substring((strHeaders.length() - 4), strHeaders.length()).equals("\r\n\r\n"))) {
// end of headers
break;
}
}
logcat的
java.lang.OutOfMemoryError
at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:140)
at java.lang.StringBuilder.append(StringBuilder.java:125)
at myApp.activity.com.getFromPLS.retreiveMetadata(getFromPLS.java:98)
at myApp.activity.com.getFromPLS.refreshMeta(getFromPLS.java:76)
at myApp.activity.com.myApp$1.run(myApp.java:371)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
錯誤可以幫我解決這個問題嗎?
非常感謝!!!!! – Peter