private Preferences pref;
private String prefString, hold;
You have declared pref
, but you have not initialized it. That is why
pref.set(prefString, hold);
throws a NullPointerException
, because null
has no function called set
. Null has nothing. Null is nothing.
Normally, I'd say you need to initialize pref with something like
pref = new Preferences();
However, according to the codenameone API for Preferences, all it's functions are static, and should be called in this way:
Preferences.set(prefString, hold);
Therefore, its declaration line should not be there to begin with.
If
Preferences.set(prefString, hold);
still throws a NullPointerException
, it is likely because 'prefString' is also null
.