0

到目前为止我已经这样做了

public void addStorage() {
    stockStore = Storage.getLocalStorageIfSupported();
    if (stockStore != null) {
        stockStore.setItem(("Index" + index), ("state" + HistoryCount));
        stockMap.put(("Index" + index), ("state" + HistoryCount));
    }
}

public void loadStorage() {
    String s;
    stockStore = Storage.getLocalStorageIfSupported();
    if (stockStore != null) {
        stockMap = new
        StorageMap(stockStore);
        for (int i = 0; i < stockStore.getLength(); i++) {
            if (stockMap.containsValue(index)) {
                s = stockStore.getItem("Index" + index);
                state = stateRecord.get(s);
                clearHighlights();
                setState(state);
                break;
            }
        }
    }
}

我不知道我错过了什么。这两个函数由它们的处理程序调用。加载并保存。load storage 将加载国际象棋的存储状态, save 将保存当前国际象棋状态。

4

1 回答 1

0

可能您在此处有错误,stockMap.containsValue(index)但应该是stockMap.containsValue("Index" + index)更正的版本:

for (int i = 0; i < stockStore.getLength(); i++) {
        if (stockMap.containsValue("Index" + index)) {
            s = stockStore.getItem("Index" + index);
            state = stateRecord.get(s);
            clearHighlights();
            setState(state);
            break;
        }
    }
于 2013-03-12T08:40:53.813 回答