1
私は1〜2週間これを理解しようとしており、できません。アプリ用のHashMapsを保存しています[CodeName One]
私は2つのクラス、MyApplication
とStore
を持っています。これは、私の格納コードに何が問題なのかを確認するためのテストプログラムです。
これはこれはMyApplication
クラス
public class MyApplication {
private Form current;
private Resources theme;
private Store o;
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
Util.register("Store", Store.class);
Toolbar.setGlobalToolbar(true);
}
public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form("Hi World");
TextField enter = new TextField("","Enter Here", 20, TextField.ANY);
Button add = new Button("Add");
add.addActionListener((ev)->
o.add(enter.getText() + "", 100)); /*Failing here*/
hi.add(enter).add(add);
hi.show();
}
private void save()
{
Storage.getInstance().writeObject("NameOfFile", o);
}
private void load()
{
o = (Store) Storage.getInstance().readObject("NameOfFile");
}
public void stop() {
current = Display.getInstance().getCurrent();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = Display.getInstance().getCurrent();
}
}
public void destroy() {
}
}
あるStore
クラス
public class Store implements Externalizable {
private static final int VERSION = 1;
HashMap<String, Integer> data;
public void externalize(DataOutputStream out) throws IOException
{
Util.writeObject(data, out);
}
public void internalize(int version, DataInputStream in) throws IOException
{
data = (HashMap<String, Integer>)Util.readObject(in);
}
public void add(String s, Integer i)
{
data.put(s, i);
}
public int getVersion()
{
return VERSION;
}
public String getObjectId()
{
return "Store";
}
}
私は以前MyApplication
クラスでハッシュマップのポインタを使用しますが、それは同じ場所で失敗しました。