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

独自空忆成欢 提交于 2020-01-16 04:27:05

问题


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?


回答1:


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.




回答2:


    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.



来源:https://stackoverflow.com/questions/8077141/blackberry-not-able-to-get-locations-sdcard-media-card-as-filesystemroot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!