Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Consilium
Posts: 13
Registered: ‎07-12-2010
My Device: Any
My Carrier: Any
Accepted Solution

Database connection - File system not ready

Hi there

 

I am using the following code.

 

 

URI uri = URI.create("/store/home/user/" + "wordHistory");

Database sqliteDB = DatabaseFactory.openOrCreate(uri, new 
DatabaseSecurityOptions(false));

 

 

This code works fine on the simulator for the blackberry 9000 but it throws the following error on the 9700 simulator.

 

net.rim.device.api.database.DatabaseIOException: File system not ready

 

Any ideas?

 

Many thanks.

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Database connection - File system not ready

The URI string should start with "file:///store/..." rather than just "/store/...".

 

Also, is this running at system startup? If so, the knowledge base article How to write safe initialization code would be good reading.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Contributor
Consilium
Posts: 13
Registered: ‎07-12-2010
My Device: Any
My Carrier: Any

Re: Database connection - File system not ready

Hi thanks for your reply.

I changed my code to use file:/// see below

 

 

private static String getDatabaseLocation() {
		String dbLocation = "/SDCard/databases/";
		System.out.println("---------------------------------------------------------debug");
		// Determine if an SDCard is present
		boolean sdCardPresent = false;
		String root = null;
		Enumeration e = FileSystemRegistry.listRoots();
		while (e.hasMoreElements()) {
			root = (String) e.nextElement();
			if (root.equalsIgnoreCase("sdcard/")) {
				sdCardPresent = true;
			}
		}
		if (!sdCardPresent) {
			// If an SDCard is not available we will store our database in
			// flash memory. This is not recommended for large databases.
			FileConnection file = null;
			try {
				file = (FileConnection) Connector.open("file:///store/home/user/", Connector.READ);
				if (file.canRead()) {
					// we have file access
					dbLocation = "file:///store/home/user/";
				} else {
					dbLocation = "file:///system/";
				}
			} catch (IOException e1) {
				e1.printStackTrace();
			}

		}
		return dbLocation;
	}

 

 

I then initialize the database using http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/832062/How_To_...

 

and the following code.

 

private void doStartupWork() {
		try {
			SqliteUtil.initializeDatabase();
		}catch (Exception e) {
			EventLogger.logEvent(Guid.eventLogId, ("An error occured!\n "  + e.toString()).getBytes(), EventLogger.ERROR);
			Dialog.inform("An error occured!\n "  + e.toString());
		}
		
	}

 

and

 

 

public static void initializeDatabase() throws IllegalArgumentException, MalformedURIException, DatabaseException {

		URI uri = URI.create(getDatabaseLocation() + "wordHistory");
		Database sqliteDB = DatabaseFactory.openOrCreate(uri, new DatabaseSecurityOptions(false));

		EventLogger.logEvent(Guid.eventLogId, ("CREATE  TABLE WordList").getBytes(), EventLogger.INFORMATION);
		Statement st = sqliteDB.createStatement("CREATE  TABLE  IF NOT EXISTS 'WordList' ('Word' TEXT check(typeof('Word') = 'text') , 'Created' TEXT, 'WordFile' BLOB)");

		st.prepare();
		st.execute();
		st.close();

		sqliteDB.close();

	}

 

 

I am still getting the same File system not ready error for the code below ( This error sill only appear for simulator 9700 JDE 5.0)

 

 

URI uri = URI.create(getDatabaseLocation() + "wordHistory");
Database sqliteDB = DatabaseFactory.openOrCreate(uri, new DatabaseSecurityOptions(false));

 

Any ideas?

 

Thanks

 

Please use plain text.
Contributor
wbasheer
Posts: 10
Registered: ‎06-18-2010
My Device: 9550
My Carrier: Sprint

Re: Database connection - File system not ready

I'm having the exact same problem and I'm trying to do the same thing (initialize my database at system startup).  If I run the debugger when the simulator is already up I don't get the error obviously but that proves that my code is correct it's just that it's trying to access the file system before it's initialized.

 

 I'm thinking of just creating another thread that just waits in a loop checking if the file system is ready.  Anybody else have any other suggestions??

 

 

Please use plain text.
Developer
JCarty
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Database connection - File system not ready

You have to wait until the system initializes before you can use any external storage. So you can use a SystemListener to listen for powerUp then try and see if you can access the card.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Please use plain text.
Contributor
wbasheer
Posts: 10
Registered: ‎06-18-2010
My Device: 9550
My Carrier: Sprint

Re: Database connection - File system not ready

I am using the SystemListener and executing the initialization of the database (accessing the file system) inside the powerUp method but it still tells me that the file system is not ready.  My problem is exactly like the original thread starter.  

 

I'm wondering if this is just a simulator issue.  I'll try different simulators to see if I can get different results.  

Please use plain text.
Developer
JCarty
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Database connection - File system not ready

And you have an "SDCard" mounted in the simulator? If you don't, it'll say the same thing.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Please use plain text.
Contributor
wbasheer
Posts: 10
Registered: ‎06-18-2010
My Device: 9550
My Carrier: Sprint

Re: Database connection - File system not ready

So in order to use file:///store....(internal memory), you have to have an SDCard connected/attached?  What I do in the initialization routine is first check if there is an SDCard and if there isn't one connected I use the file:///store/.... memory.  I have gotten it to work correctly with an SDCard as well.  I'm almost 100% sure this is an issue with the memory not being ready while I'm accessing it at startup and that startup check/system listener is not working.  I'm not understanding what the SDCard has to do with anything.

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Database connection - File system not ready

You do not need an SDCard to use file:///store/... Can you show us your main() function and the c'tor for the application class? My suspicion is still about exactly when the db initialization code is running.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Contributor
wbasheer
Posts: 10
Registered: ‎06-18-2010
My Device: 9550
My Carrier: Sprint

Re: Database connection - File system not ready

Yes I've pretty much copied the same structure as the example.  Here is the code:

 

 

public static void main(String[] args) 
{

	// Entry point for the application when the application icon is 	// selected
	if (args != null && args.length > 0 && args[0].equals("gui")) 
	{
		TVisMobile theApp = new TVisMobile(true);
		theApp.setAppInstanceType(APP_INSTANCE_GUI);
		theApp.enterEventDispatcher();
	}

	// Entry point for the application at phone startup
	else 
	{
		TVisMobile theApp = new TVisMobile(false);
		theApp.setAppInstanceType(APP_INSTANCE_LISTENER);

		EncodedImage mImage = EncodedImage.getEncodedImageResource("AlertIcon.png");
		ApplicationIcon mIcon = new ApplicationIcon(mImage);
		ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
		reg.register(mIcon, false, false);
			
		if(ApplicationManager.getApplicationManager().inStartup())
		{
			theApp.addSystemListener(theApp);
		}
		else
		{
			_listener = new ListeningThread();
			_listener.start();
		}

		theApp.enterEventDispatcher();
	}
}

 

The listening thread is where I access the memory where I receive the error.   Here is where I'm calling that:

 

 

public void powerUp() 
{
	removeSystemListener(this);
	
	_listener = new ListeningThread();
	_listener.start();
	
}

 

 

 

Now I can post what's inside the listening thread but it shouldn't matter right?  Let me know if you need to see more code.

 

Please use plain text.