07-18-2010 10:33 AM
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.
Solved! Go to Solution.
07-18-2010 11:21 AM
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.
07-19-2010 03:01 AM
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/li
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
07-19-2010 08:06 PM
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??
07-20-2010 12:15 AM
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.
07-20-2010 10:05 AM
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.
07-20-2010 01:50 PM
07-20-2010 06:40 PM
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.
07-20-2010 06:51 PM
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.
07-22-2010 12:09 PM
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.pn g");
ApplicationIcon mIcon = new ApplicationIcon(mImage);
ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
reg.register(mIcon, false, false);
if(ApplicationManager.getApplicationManager().inSt artup())
{
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.