Troubleshooting guide
73
3: Storing data
public void run() {
synchronized(store) {
String websiteUrl = websitefield.getText();
if (websiteUrl.length() == 0) {
Dialog.alert(_resources.getString(ALERT_NO_WEBSITE));
} else {
BrowserSession visit = Browser.getDefaultSession();
visit.displayPage(websiteUrl);
}
}
}
};
static {
_resources = ResourceBundle.getBundle(
RestaurantResource.BUNDLE_ID,
RestaurantResource.BUNDLE_NAME);
store = PersistentStore.getPersistentObject(0xdec6a67096f833cL);
// Key is hash of test.samples.restaurants.
synchronized (store) {
_data = (Vector)store.getContents();
if (_data == null) {
_data = new Vector();
store.setContents( _data );
store.commit();
}
}
}
public static void main(String[] args) {
Restaurants app = new Restaurants();
app.enterEventDispatcher();
}
private static final class RestaurantInfo implements Persistable {
// Data.
private String[] _elements;
// Fields.
public static final int NAME = 0;
public static final int ADDRESS = 1;
public static final int PHONE = 2;
public static final int WEBSITE = 3;
public static final int SPECIALTY = 4;
public RestaurantInfo() {
_elements = new String[4];
for ( int i = 0; i < _elements.length; ++i) {
_elements[i] = ““;
}
}
public String getElement(int id) {
return _elements[id];
}
public void setElement(int id, String value) {