sid_sket
sid_sket

Reputation: 81

Blackberry: Not able to get locations SDCard/Media Card as fileSystemRoot?

I want to openOrCreate database in SDcard / Media Card. When i run the application in device (BlackBerry Curve 8900), i find only one root i.e "system/" and running application in simulator (9500), i find three roots as shown in comment in code. I am getting error at;

  _db = DatabaseFactory.openOrCreate(_uri); 
  (error: Method "toString" with signature "()Ljava/lang/String;" is not applicable on this object)

And i am not able to understand what is this error about. Here is the code.

public void getValues() throws Exception
{

    boolean sdCardPresent = false;
    String root = null;
    Enumeration e = FileSystemRegistry.listRoots();
    while (e.hasMoreElements())
    {
        root = (String)e.nextElement();
        System.out.println("Value of root::" +root); // value of root = "system/" when run in device and
                                                     // value of root = "store/" "SDCard/" "system/" when run in simulator 
        if(root.equalsIgnoreCase("system/"))
        {
            sdCardPresent = true;
        }     
    }         
    System.out.println("--------------------getValues()----------------------------------");
    URI _uri = URI.create(Global.DB_PATH + Global.DB_Main);
    System.out.println("Valud of uri::" +_uri);
    _db = DatabaseFactory.openOrCreate(_uri); //getting error here. 
    System.out.println("Valud of _db::" +_db);
    _db.close();

I tried these three paths, getting output with "/store"(when run in simulator) but error with rest two paths.Even using "/store" in device is showing the same error.

Global.DB_PATH = "/MediaCard/databases/";
Global.DB_PATH = "/SDCard/databases/";
Global.DB_PATH = "/store/databases/";

Is there any way how to get SDCard/Media Card as root so that i can copy the database in there?

Upvotes: 1

Views: 717

Answers (2)

Vit Khudenko
Vit Khudenko

Reputation: 28418

My guess is when you are running your app on a real device you have USB cable plugged in to the device. If this is the case, try to unplug the cable and rerun the app. You may use Dialog.inform() to quickly check what roots you get this time.

Upvotes: 3

V.J.
V.J.

Reputation: 9580

    private ObjectListField getFileList() {
    if (fileList == null) {
        fileList = new ObjectListField();
        String[] roots = new String[3];
        Enumeration enum = FileSystemRegistry.listRoots();
        int x = 0;
        while (enum.hasMoreElements()) {
            if (x < 3) {
                roots[x] = enum.nextElement().toString();
            }
            x++;
        }
        enum = FileSystemRegistry.listRoots();
        fileList.set((roots[2] != null) ? roots : new String[]{"system/", "SDCard/", "store/"});
    }
    return fileList;
}

Try this code.

Upvotes: -1

Related Questions