GSON fromJson stackOverflowError

时间:2014-12-06 16:39:48

标签: java android gson stack-overflow

我正在尝试解析以下json

{
  "Id": "233ffba3-9796-4fff-32e3-535116e1297c",
  "Content": "lorem ipsum",
  "DateCreated": "2014-12-06T16:02:25Z",
  "ChatId": "33485bff-a95f-4a19-982d-532364db384d",
  "AccountId": "2da98191-c3de-49f0-a424-89ba7a0f448e",
  "Internal": false,
  "Quotation": false
}

到这个班级

public class Message extends Syncable<Message> implements Comparable<Message> {

    public UUID Id;
    public String Content;
    public Date DateCreated;
    public UUID ChatId;
    public UUID AccountId;
    public Boolean Internal;
    public Boolean Quotation;
    public Account Account;
    public Chat Chat;
    public Centipede<MessageRead> MessageRead;

    public Message() {
        this.MessageRead = new Centipede<MessageRead>();
    }
}

得到这个奇怪的错误

java.lang.StackOverflowError
        at java.nio.MappedByteBuffer.<init>(MappedByteBuffer.java:43)
        at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:33)
        at java.nio.DirectByteBuffer.copy(DirectByteBuffer.java:52)
        at java.nio.DirectByteBuffer.duplicate(DirectByteBuffer.java:75)
        at com.android.dex.Dex.open(Dex.java:191)
        at com.android.dex.Dex$StringTable.get(Dex.java:893)
        at com.android.dex.Dex$StringTable.get(Dex.java:890)
        at java.lang.Class.getDexCacheString(Class.java:1334)
        at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:731)
        at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:705)
        at libcore.reflect.AnnotationAccess.getSignature(AnnotationAccess.java:453)
        at java.lang.Class.getGenericSuperclass(Class.java:824)
        at com.google.gson.internal.$Gson$Types.getGenericSupertype($Gson$Types.java:249)

昨天一切正常,今天,Android Studio更新后,我收到了这个错误。

2 个答案:

答案 0 :(得分:0)

更新后可能您的Gson库丢失了 试试这个

1)将Gson jar(在我的情况下,gson-2.2.4.jar)放入libs文件夹

2)右键单击它并点击'Add as library'

3)确保compile files('libs/gson-2.2.4.jar')文件中包含build.gradle

4)做一个干净的建筑

答案 1 :(得分:0)

尝试从UUID更改为String,看看是否有效。