Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Gson通过重新启动应用程序枚举松散值_Java_Android_Gson - Fatal编程技术网

Java Gson通过重新启动应用程序枚举松散值

Java Gson通过重新启动应用程序枚举松散值,java,android,gson,Java,Android,Gson,我正在做的游戏,有一些影响,而发挥 public enum Effect { DoublePoints(), IncreaseSwitch(), ShowOne(), ShowSame(); @SerializedName("stored") int stored; @SerializedName("leftTime") int leftTime; Effect() {

我正在做的游戏,有一些影响,而发挥

public enum Effect {
    DoublePoints(),
    IncreaseSwitch(),
    ShowOne(),
    ShowSame();

    @SerializedName("stored")
    int stored;
    @SerializedName("leftTime")
    int leftTime;

    Effect() {

    }

    public int getStored() {
        return stored;
    }

    public void setStored(int stored) {
        this.stored = stored;
    }

    public int getLeftTime() {
        return leftTime;
    }

    public void setLeftTime(int leftTime) {
        this.leftTime = leftTime;
    }
}
使用
存储
检查我的效果计数,
leftTime
是效果结束前的时间

为了有效地读写,我在运行时使用
HashMap
处理效果

private Map<String, EnumCollection.Effect> gameEffects = new HashMap<>();
现在

我可以成功关闭和打开应用程序。在数据库中成功写入和读取数据

通过应用程序的repen,我已经存储并保留了预期的时间值

但是

当我用
Android Studio
rerun按钮重新启动应用程序时,存储时间和leftTime为0

当我记录效果字符串时,我收到:

effects: {"ShowSame":"ShowSame","DoublePoints":"DoublePoints","ShowOne":"ShowOne","IncreaseSwitch":"IncreaseSwitch"}
使用
@SerializedName
是否应存储值

我错过了什么


TypeToken
是否存在一些问题?

通过从
enum
转到
Object

public class EffectItem {

    int stored;
    int leftTime;

    public int getStored() {
        return stored;
    }

    public void setStored(int stored) {
        this.stored = stored;
    }

    public int getLeftTime() {
        return leftTime;
    }

    public void setLeftTime(int leftTime) {
        this.leftTime = leftTime;
    }
}
从此

Type collectionType = new TypeToken<HashMap<String, EffectItem>>() {
}.getType();
gameEffects = new Gson().fromJson(game.getEffects(), collectionType);

仍然可以用来更好地访问特效

保存元素的数据库在哪里?外部还是内部安卓?@bug,内部。是
领域
Type collectionType = new TypeToken<HashMap<String, EffectItem>>() {
}.getType();
gameEffects = new Gson().fromJson(game.getEffects(), collectionType);
private Map<String, EffectItem> gameEffects = new HashMap<>();