BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-07-2009, 10:22 AM   #1 (permalink)
New Member
 
newbie_bb's Avatar
 
Join Date: Aug 2009
Model: 8300
PIN: N/A
Carrier: simulator
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Error while persisting the data in mobile phone ..

Please Login to Remove!

Hi All,
I am facing problem while persisting my data.
I followed the example provided at
http :// na.blackberry.com /developers/resources/A13_Storing_Persistent_Data_V2.pdf

First i copy paste the code in a project. It was working fine. Later I re managed the code for my use as follows.

Intially it was running fine, but even at that time it was not saving the data. Later, some how my eclipse was not able to attach to the simulator debugger.

Later after a fresh installation it worked without error but was not saving the data. Again my luck gives a shock,debugger gives a problem and
Configuration config = StoreConfiguration.getConfiguration(); of settings.java starts throwing null pointer exception.

Please let me know where I am wrong.

Class one Settings.java

Code:
package com.persistence;

import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;

public class Settings extends MainScreen
{

	public static String mostPopular = "mostpopular";
	public static String newlyadded = "newlyadded";
	public static String news = "news";
		
	CheckboxField chkMostPopular;
	CheckboxField chkNewlyAdded;
	CheckboxField chkNews;
	
	ButtonField saveFields;

	public Settings()
	{
		try
		{
			Configuration config = StoreConfiguration.getConfiguration();
			if(config != null)
			{
				chkMostPopular = new CheckboxField("Most Popular", ((Boolean)config.getElement(mostPopular)).booleanValue());
				chkNewlyAdded = new CheckboxField("Newly Added", ((Boolean)config.getElement(newlyadded)).booleanValue());
				chkNews = new CheckboxField("News", ((Boolean)config.getElement(news)).booleanValue());
			}
			else
			{
				chkMostPopular = new CheckboxField("Most Popular", false);
				chkNewlyAdded = new CheckboxField("Newly Added", false);
				chkNews = new CheckboxField("News", false);
			}
			
			
			saveFields = new ButtonField("Save")
			{
				protected boolean navigationClick(int status, int time)
				{
					persistConfigurationData();
					Dialog.alert("Data saved");
					//onClose();
					return super.navigationClick(status, time);
				}
			};
			add(chkMostPopular);
			add(chkNewlyAdded);
			add(chkNews);
			add(saveFields);
		}
		catch (Exception e)
		{
			System.out.println("##### Error occurred Settings() "+e.getMessage());
		}
	}
	
	private void persistConfigurationData()
	{
		Configuration config = new Configuration();
		config.setElement(mostPopular,new Boolean(chkMostPopular.getChecked()));
		config.setElement(newlyadded,new Boolean(chkNewlyAdded.getChecked()));
		config.setElement(news,new Boolean(chkNews.getChecked()));
		System.out.println("Going to persist object");
		StoreConfiguration.setConfiguration(config);
	}
}
Class Second: Configuration.java

Code:
package com.persistence;

import java.util.Hashtable;

import net.rim.device.api.util.Persistable;

public class Configuration implements Persistable
{
	private static Hashtable _config;
	public Configuration()
	{
		_config = new Hashtable();
	}
	
	public Object getElement(String key)
	{
		return _config.get(key);
	}
	public void setElement(String key, boolean value)
	{
		_config.put(key, new Boolean(value));
	}
	
	public void setElement(String key, Boolean value)
	{
		_config.put(key,value);
	}
	
	public Hashtable getConfiguration()
	{
		return _config;
	}
	
	public boolean isEmpty()
	{
		return _config.isEmpty();
	}
}
Class Third: StoreConfiguration.java

Code:
package com.persistence;

import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;

public class StoreConfiguration
{
	private static PersistentObject store;
	private static Configuration _data;
	
	public StoreConfiguration()
	{
		
	}
	
	static
	{
		//store = PersistentStore.getPersistentObject(0xdec7a67096f833cL);
		store = PersistentStore.getPersistentObject(0xe63e08aacd575338L);
		_data = new Configuration();
	}
	
	public static Configuration getConfiguration()
	{
		synchronized(store)
		{
			Object storedObject = store.getContents();
			if(storedObject == null)
			{
				System.out.println("getConfiguration  ## _data is empty.");
			}
			else
			{
				_data = (Configuration) store.getContents();
			}
		}
		return _data;
		
	}
	
	public static void setConfiguration(Configuration configuration)
	{
		System.out.println("setConfiguration  ## Going to persist object");
		_data = configuration;
		System.out.println("setConfiguration  ## _data "+((Boolean)_data.getElement("mostpopular")).booleanValue());
		synchronized (store)
		{
			store.setContents(_data);
			store.commit();
		}
	}
}
Please let me know where i am going wrong ......

Thanks in advance ..
__________________

Thanks,
Regards,
Amber
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

VINTAGE 1930s HARLEY DAVIDSON VL VLH ALUMINUM VETERAN GAS FUEL PETROL OIL TANK
$1099.0
VINTAGE 1930s HARLEY DAVIDSON VL VLH  ALUMINUM  VETERAN GAS FUEL PETROL OIL TANK pictureR35 1935 & LATER MOTORCYCLE REAR FENDER MUDGUARD VINTAGE RARE FOR BMW OLD,
$240.99
R35 1935 & LATER MOTORCYCLE REAR FENDER MUDGUARD VINTAGE RARE FOR BMW OLD, pictureVintage Starrett 436 1 Inch Micrometer
$44.99
Vintage Starrett 436 1 Inch Micrometer pictureMONZA CAP 2.5" OIL GAS FUEL PETROL TANK FOR VINTAGE CLASSIC BENTLEY WESTFIELD ,
$45.99
MONZA CAP 2.5Vintage Weston AC Voltmeter Model 433 Steampunk Industrial 25-2400 Cycles 0-150V
$24.99
Vintage Weston AC Voltmeter Model 433 Steampunk Industrial 25-2400 Cycles 0-150V picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.