如何处理android中的webservices的大响应

时间:2011-02-26 11:27:32

标签: android

我从webservice获得了很大的价值。我的回复就像XML实体字符引用一样。我正在使用strigescapeutils calss替换字符。我将我的回复存储在一个字符串中。我收到内存不足错误。我正在使用SAX解析器解析响应。我解析了该值并将其存储在bean的arraylist中。在arraylist值中将其添加到textview中。

执行此操作时出现此错误:内存不足错误。我不知道怎么做流。谁能告诉我怎么做?谁能举个例子?是否可以在bean和字符串的arraylist中添加大值?

这是我使用字符串解析器读取解析值:

 xr.parse(new InputSource(new StringReader(webservicevalue)));

我收到此错误:

I/dalvikvm(  418):   at android.view.ViewGroup.addInArray(ViewGroup.java:~1918)
I/dalvikvm(  418):   at android.view.ViewGroup.addViewInner(ViewGroup.java:1879)

I/dalvikvm(  418):   at android.view.ViewGroup.addView(ViewGroup.java:1756)
I/dalvikvm(  418):   at android.widget.TableLayout.addView(TableLayout.java:418)

I/dalvikvm(  418):   at android.view.ViewGroup.addView(ViewGroup.java:1713)
I/dalvikvm(  418):   at android.widget.TableLayout.addView(TableLayout.java:400)

I/dalvikvm(  418):   at android.view.ViewGroup.addView(ViewGroup.java:1693)
I/dalvikvm(  418):   at android.widget.TableLayout.addView(TableLayout.java:391)

I/dalvikvm(  418):   at com.inquest.HomeSearchArticle$HomeSearchTask.onPostExecu
te(HomeSearchArticle.java:210)
I/dalvikvm(  418):   at com.inquest.HomeSearchArticle$HomeSearchTask.onPostExecu
te(HomeSearchArticle.java:1)
I/dalvikvm(  418):   at android.os.AsyncTask.finish(AsyncTask.java:417)
I/dalvikvm(  418):   at android.os.AsyncTask.access$300(AsyncTask.java:127)
I/dalvikvm(  418):   at android.os.AsyncTask$InternalHandler.handleMessage(Async
Task.java:429)
I/dalvikvm(  418):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm(  418):   at android.os.Looper.loop(Looper.java:123)
I/dalvikvm(  418):   at android.app.ActivityThread.main(ActivityThread.java:4363
)
I/dalvikvm(  418):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm(  418):   at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm(  418):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.r
un(ZygoteInit.java:860)
I/dalvikvm(  418):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
618)
I/dalvikvm(  418):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(  418):
I/System.out(  418): ######out of memory error is###java.lang.OutOfMemoryError
W/System.err(  418): java.lang.OutOfMemoryError
W/System.err(  418):    at android.view.ViewGroup.addInArray(ViewGroup.java:1918
)
W/System.err(  418):    at android.view.ViewGroup.addViewInner(ViewGroup.java:18
79)
W/System.err(  418):    at android.view.ViewGroup.addView(ViewGroup.java:1756)
W/System.err(  418):    at android.widget.TableLayout.addView(TableLayout.java:4
18)
W/System.err(  418):    at android.view.ViewGroup.addView(ViewGroup.java:1713)
W/System.err(  418):    at android.widget.TableLayout.addView(TableLayout.java:4
00)
W/System.err(  418):    at android.view.ViewGroup.addView(ViewGroup.java:1693)
W/System.err(  418):    at android.widget.TableLayout.addView(TableLayout.java:3
91)
W/System.err(  418):    at com.inquest.HomeSearchArticle$HomeSearchTask.onPostEx
ecute(HomeSearchArticle.java:210)
W/System.err(  418):    at com.inquest.HomeSearchArticle$HomeSearchTask.onPostEx
ecute(HomeSearchArticle.java:1)
W/System.err(  418):    at android.os.AsyncTask.finish(AsyncTask.java:417)
W/System.err(  418):    at android.os.AsyncTask.access$300(AsyncTask.java:127)
W/System.err(  418):    at android.os.AsyncTask$InternalHandler.handleMessage(As
yncTask.java:429)
W/System.err(  418):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(  418):    at android.os.Looper.loop(Looper.java:123)
W/System.err(  418):    at android.app.ActivityThread.main(ActivityThread.java:4
363)
W/System.err(  418):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(  418):    at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err(  418):    at com.android.internal.os.ZygoteInit$MethodAndArgsCalle
r.run(ZygoteInit.java:860)
W/System.err(  418):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.ja
va:618)
W/System.err(  418):    at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm-heap(  418): Clamp target GC heap from 17.250MB to 16.000MB
D/dalvikvm(  418): GC freed 8999 objects / 786288 bytes in 466ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.467MB to 16.000MB
D/dalvikvm(  418): GC freed 9064 objects / 514760 bytes in 485ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.583MB to 16.000MB
D/dalvikvm(  418): GC freed 5354 objects / 317512 bytes in 450ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.583MB to 16.000MB
D/dalvikvm(  418): GC freed 670 objects / 20232 bytes in 534ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.588MB to 16.000MB
D/dalvikvm(  418): GC freed 1238 objects / 46104 bytes in 445ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.590MB to 16.000MB
D/dalvikvm(  418): GC freed 242 objects / 9944 bytes in 429ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.620MB to 16.000MB
D/dalvikvm(  418): GC freed 595 objects / 52232 bytes in 426ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.619MB to 16.000MB
D/dalvikvm(  418): GC freed 298 objects / 9024 bytes in 398ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.666MB to 16.000MB
D/dalvikvm(  418): GC freed 914 objects / 79712 bytes in 439ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.711MB to 16.000MB
D/dalvikvm(  418): GC freed 1378 objects / 94048 bytes in 467ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.710MB to 16.000MB
D/dalvikvm(  418): GC freed 176 objects / 4432 bytes in 492ms
I/dalvikvm-heap(  418): Forcing collection of SoftReferences for 1028-byte alloc
ation
I/dalvikvm-heap(  418): Clamp target GC heap from 17.709MB to 16.000MB
D/dalvikvm(  418): GC freed 81 objects / 1296 bytes in 714ms
E/dalvikvm-heap(  418): Out of memory on a 1028-byte allocation.
I/dalvikvm(  418): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm(  418):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b268 self=0
xbd00
I/dalvikvm(  418):   | sysTid=418 nice=0 sched=0/0 cgrp=default handle=-13440013
84
I/dalvikvm(  418):   at android.text.StaticLayout.generate(StaticLayout.java:~13
8)
I/dalvikvm(  418):   at android.text.StaticLayout.<init>(StaticLayout.java:97)
I/dalvikvm(  418):   at android.text.StaticLayout.<init>(StaticLayout.java:54)
I/dalvikvm(  418):   at android.text.StaticLayout.<init>(StaticLayout.java:45)
I/dalvikvm(  418):   at android.widget.TextView.makeNewLayout(TextView.java:4914
)
I/dalvikvm(  418):   at android.widget.TextView.onMeasure(TextView.java:5176)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.widget.TableRow.getColumnsWidths(TableRow.java:3
08)
I/dalvikvm(  418):   at android.widget.TableLayout.findLargestCells(TableLayout.
java:497)
I/dalvikvm(  418):   at android.widget.TableLayout.measureVertical(TableLayout.j
ava:462)
I/dalvikvm(  418):   at android.widget.TableLayout.onMeasure(TableLayout.java:42
8)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.widget.ScrollView.measureChildWithMargins(Scroll
View.java:893)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.widget.ScrollView.onMeasure(ScrollView.java:276)

I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.widget.RelativeLayout.measureChildHorizontal(Rel
ativeLayout.java:569)
I/dalvikvm(  418):   at android.widget.RelativeLayout.onMeasure(RelativeLayout.j
ava:361)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.widget.RelativeLayout.measureChildHorizontal(Rel
ativeLayout.java:569)
I/dalvikvm(  418):   at android.widget.RelativeLayout.onMeasure(RelativeLayout.j
ava:361)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.LinearLayout.measureChildBeforeLayout(Lin
earLayout.java:888)
I/dalvikvm(  418):   at android.widget.LinearLayout.measureHorizontal(LinearLayo
ut.java:619)
I/dalvikvm(  418):   at android.widget.LinearLayout.onMeasure(LinearLayout.java:
280)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewGroup.measureChildWithMargins(ViewGroup
.java:3023)
I/dalvikvm(  418):   at android.widget.FrameLayout.onMeasure(FrameLayout.java:24
5)
I/dalvikvm(  418):   at android.view.View.measure(View.java:7964)
I/dalvikvm(  418):   at android.view.ViewRoot.performTraversals(ViewRoot.java:76
3)
I/dalvikvm(  418):   at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
I/dalvikvm(  418):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm(  418):   at android.os.Looper.loop(Looper.java:123)
I/dalvikvm(  418):   at android.app.ActivityThread.main(ActivityThread.java:4363
)
I/dalvikvm(  418):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm(  418):   at java.lang.reflect.Method.invoke(Method.java:521)
I/dalvikvm(  418):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.r
un(ZygoteInit.java:860)
I/dalvikvm(  418):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
618)
I/dalvikvm(  418):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(  418):
D/AndroidRuntime(  418): Shutting down VM
W/dalvikvm(  418): threadid=3: thread exiting with uncaught exception (group=0x4
001b188)
E/AndroidRuntime(  418): Uncaught handler: thread main exiting due to uncaught e
xception
I/dalvikvm-heap(  418): Clamp target GC heap from 17.723MB to 16.000MB
D/dalvikvm(  418): GC freed 309 objects / 11840 bytes in 425ms
I/dalvikvm-heap(  418): Clamp target GC heap from 17.723MB to 16.000MB
D/dalvikvm(  418): GC freed 39 objects / 3144 bytes in 402ms
I/dalvikvm-heap(  418): Forcing collection of SoftReferences for 1402-byte alloc
ation
I/dalvikvm-heap(  418): Clamp target GC heap from 17.723MB to 16.000MB
D/dalvikvm(  418): GC freed 0 objects / 0 bytes in 448ms
E/dalvikvm-heap(  418): Out of memory on a 1402-byte allocation.
I/dalvikvm(  418): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm(  418):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b268 self=0
xbd00
I/dalvikvm(  418):   | sysTid=418 nice=0 sched=0/0 cgrp=default handle=-13440013
84
I/dalvikvm(  418):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractSt
ringBuilder.java:~97)
I/dalvikvm(  418):   at java.lang.AbstractStringBuilder.append0(AbstractStringBu
ilder.java:131)
I/dalvikvm(  418):   at java.lang.StringBuffer.append(StringBuffer.java:273)
I/dalvikvm(  418):   at java.io.StringWriter.write(StringWriter.java:138)
I/dalvikvm(  418):   at java.io.PrintWriter.doWrite(PrintWriter.java:711)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:686)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:661)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:729)
I/dalvikvm(  418):   at java.io.PrintWriter.print(PrintWriter.java:492)
I/dalvikvm(  418):   at java.io.PrintWriter.println(PrintWriter.java:623)
I/dalvikvm(  418):   at java.lang.Throwable.printStackTrace(Throwable.java:316)
I/dalvikvm(  418):   at android.util.Log.getStackTraceString(Log.java:234)
I/dalvikvm(  418):   at com.android.internal.os.RuntimeInit.crash(RuntimeInit.ja
va:315)
I/dalvikvm(  418):   at com.android.internal.os.RuntimeInit$UncaughtHandler.unca
ughtException(RuntimeInit.java:76)
I/dalvikvm(  418):   at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java
:887)
I/dalvikvm(  418):   at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java
:884)
I/dalvikvm(  418):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(  418):
I/dalvikvm-heap(  418): Clamp target GC heap from 17.728MB to 16.000MB
D/dalvikvm(  418): GC freed 88 objects / 7896 bytes in 426ms
I/dalvikvm-heap(  418): Forcing collection of SoftReferences for 1126-byte alloc
ation
I/dalvikvm-heap(  418): Clamp target GC heap from 17.728MB to 16.000MB
D/dalvikvm(  418): GC freed 0 objects / 0 bytes in 429ms
E/dalvikvm-heap(  418): Out of memory on a 1126-byte allocation.
I/dalvikvm(  418): "main" prio=5 tid=3 RUNNABLE
I/dalvikvm(  418):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001b268 self=0
xbd00
I/dalvikvm(  418):   | sysTid=418 nice=0 sched=0/0 cgrp=default handle=-13440013
84
I/dalvikvm(  418):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractSt
ringBuilder.java:~97)
I/dalvikvm(  418):   at java.lang.AbstractStringBuilder.append0(AbstractStringBu
ilder.java:131)
I/dalvikvm(  418):   at java.lang.StringBuffer.append(StringBuffer.java:273)
I/dalvikvm(  418):   at java.io.StringWriter.write(StringWriter.java:138)
I/dalvikvm(  418):   at java.io.PrintWriter.doWrite(PrintWriter.java:711)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:686)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:661)
I/dalvikvm(  418):   at java.io.PrintWriter.write(PrintWriter.java:729)
I/dalvikvm(  418):   at java.io.PrintWriter.print(PrintWriter.java:492)
I/dalvikvm(  418):   at java.io.PrintWriter.println(PrintWriter.java:623)
I/dalvikvm(  418):   at java.lang.Throwable.printStackTrace(Throwable.java:316)
I/dalvikvm(  418):   at android.util.Log.getStackTraceString(Log.java:234)
I/dalvikvm(  418):   at com.android.internal.os.RuntimeInit.crash(RuntimeInit.ja
va:323)
I/dalvikvm(  418):   at com.android.internal.os.RuntimeInit$UncaughtHandler.unca
ughtException(RuntimeInit.java:76)
I/dalvikvm(  418):   at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java
:887)
I/dalvikvm(  418):   at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java
:884)
I/dalvikvm(  418):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm(  418):
I/Process (   58): Sending signal. PID: 418 SIG: 3
I/dalvikvm(  418): threadid=7: reacting to signal 3
I/dalvikvm(  418): Wrote stack trace to '/data/anr/traces.txt'
I/Process (  418): Sending signal. PID: 418 SIG: 9
I/ActivityManager(   58): Process com.inquest (pid 418) has died.
I/WindowManager(   58): WIN DEATH: Window{43ce0a18 com.inquest/com.inquest.Login
Activity1 paused=false}
I/WindowManager(   58): WIN DEATH: Window{43d6b028 com.inquest/com.inquest.HomeA
ctivityGroup paused=false}
I/WindowManager(   58): WIN DEATH: Window{43dab588 com.inquest/com.inquest.Hello
TabWidget paused=false}
I/ActivityManager(   58): Start proc com.inquest for activity com.inquest/.Login
Activity1: pid=428 uid=10026 gids={3003, 1015}
D/dalvikvm(   29): GC freed 312 objects / 12104 bytes in 337ms
D/dalvikvm(   29): GC freed 52 objects / 2296 bytes in 338ms
D/ddm-heap(  428): Got feature list request
D/dalvikvm(   29): GC freed 2 objects / 56 bytes in 292ms
I/UsageStats(   58): Unexpected resume of com.inquest while already resumed in c
om.inquest
W/InputManagerService(   58): Got RemoteException sending setActive(false) notif
ication to pid 418 uid 10026
I/ActivityManager(   58): Displayed activity com.inquest/.LoginActivity1: 4444 m
s (total 4444 ms)

1 个答案:

答案 0 :(得分:1)

好的,您正在从Web服务接收一些XML,并且您正在使用SAX解析此XML。 SAX是一种流式解析器,它只读取XML文档的块,因此允许最小化所需的内存。所以这部分程序按预期工作。

然后将数据存储在ArrayList中,这意味着在内存中。你没有说你要解析多少条目,但我认为这就是问题所在。您应该将条目存储在数据库中。因此,您应该使用ContentProvider。您可以找到一个保存和显示数据的好教程here - 官方记事本练习1。