gpt4 book ai didi

java - Simpleframework 树反序列化时出现 java.lang.StackOverflowError

转载 作者:行者123 更新时间:2023-12-01 14:36:44 24 4
gpt4 key购买 nike

我有一个大型 xml 树,其结构如下:

<?xml version="1.0"?>
<SampleElem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Children>
<SampleElem>
<Children/>
<Id>1</Id>
<Value>Test2</Value>
</SampleElem>
</Children>
<Id>-1</Id>
<Value>Test1</Value>
</SampleElem>

我正在尝试使用 simpleframework 反序列化它:

Serializer serializer = new Persister();
SampleElem root = serializer.read(SampleElem.class, someStream, false);

一段时间后,应用程序因错误而停止。从设备登录:

E/AndroidRuntime(13591): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(13591): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(13591): at android.os.AsyncTask$3.done(AsyncTask.java:200)
E/AndroidRuntime(13591): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
E/AndroidRuntime(13591): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
E/AndroidRuntime(13591): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
E/AndroidRuntime(13591): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
E/AndroidRuntime(13591): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
E/AndroidRuntime(13591): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
E/AndroidRuntime(13591): at java.lang.Thread.run(Thread.java:1019)
E/AndroidRuntime(13591): Caused by: java.lang.StackOverflowError
E/AndroidRuntime(13591): at java.lang.StringBuilder.append(StringBuilder.java:217)
E/AndroidRuntime(13591): at java.lang.reflect.Modifier.toString(Modifier.java:285)
E/AndroidRuntime(13591): at java.lang.reflect.Method.toString(Method.java:538)
E/AndroidRuntime(13591): at java.lang.reflect.Method.equals(Method.java:361)
E/AndroidRuntime(13591): at org.apache.harmony.lang.annotation.AnnotationFactory.invoke(AnnotationFactory.java:307)
E/AndroidRuntime(13591): at $Proxy1.inline(Native Method)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.ElementListLabel.getConverter(ElementListLabel.java:160)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.CacheLabel.getConverter(CacheLabel.java:280)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readVariable(Composite.java:604)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.read(Composite.java:201)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.read(Composite.java:148)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.CompositeList.populate(CompositeList.java:175)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.CompositeList.read(CompositeList.java:120)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.read(Composite.java:201)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.read(Composite.java:148)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.CompositeList.populate(CompositeList.java:175)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.CompositeList.read(CompositeList.java:120)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.read(Composite.java:201)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.read(Composite.java:148)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.CompositeList.populate(CompositeList.java:175)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.CompositeList.read(CompositeList.java:120)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
E/AndroidRuntime(13591): at org.simpleframework.xml.core.Compos

数据完全正确,输入的xml完全有效。你有什么想法吗?

谢谢!

更新:

TreeStrategy 怎么样?应该如何使用呢?你有什么例子吗?

最佳答案

您无法在 Android 上更改默认堆栈大小或现有线程的堆栈大小。但是,您可以在创建线程时设置堆栈大小。使用完整的构造函数:

public Thread(ThreadGroup group, Runnable runnable, String threadName, long stackSize)

您可以将堆栈大小设置为最大 256KB。

因此,您的情况的策略是创建一个具有深堆栈的新线程,并在该线程上运行此解析代码。

关于java - Simpleframework 树反序列化时出现 java.lang.StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16429023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com