如下面的代码,执行后报java.lang.StackOverflowError错误:
MusicSavedInfo musicSavedInfo=new MusicSavedInfo(currentStartTime,openOrCloseFlag,currentDayFlags,currentSelectMusicTitle,currentSelectMusicPath,"1"); String jsonData=gson.toJson(musicSavedInfo);我手机4.1的系统,执行正常不会报错;到4.4的系统上就报下面的错误
06-25 20:31:50.092: E/AndroidRuntime(25122): java.lang.StackOverflowError 06-25 20:31:50.092: E/AndroidRuntime(25122): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380) 06-25 20:31:50.092: E/AndroidRuntime(25122): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375) 06-25 20:31:50.092: E/AndroidRuntime(25122): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380) 06-25 20:31:50.092: E/AndroidRuntime(25122): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375) 06-25 20:31:50.092: E/AndroidRuntime(25122): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380) 06-25 20:31:50.092: E/AndroidRuntime(25122): at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)最后把gson-2.1.jar换成gson-1.7.1.jar,即4.4系统也能执行通过,虽然一时不知道为什么,但算是解决了。
gson-1.7.1.jar包下载地址:gson-1.7.1.jar
Android 执行 gson.toJson(object) 报java.lang.StackOverflowError异常
原文地址:http://blog.csdn.net/lilidejing/article/details/46642205