Blackberry:无法获取SD卡/媒体卡作为文件系统根目录的位置?
我想在SD卡/媒体卡中打开或创建数据库。当我在设备(BlackBerry Curve 8900)中运行应用程序时,我只找到一个根,即“system/”和在模拟器中运行应用程序(9500),我找到三个根,如代码中的注释所示。我在这方面出错了Blackberry:无法获取SD卡/媒体卡作为文件系统根目录的位置?,blackberry,Blackberry,我想在SD卡/媒体卡中打开或创建数据库。当我在设备(BlackBerry Curve 8900)中运行应用程序时,我只找到一个根,即“system/”和在模拟器中运行应用程序(9500),我找到三个根,如代码中的注释所示。我在这方面出错了 _db = DatabaseFactory.openOrCreate(_uri); (error: Method "toString" with signature "()Ljava/lang/String;" is not applicable o
_db = DatabaseFactory.openOrCreate(_uri);
(error: Method "toString" with signature "()Ljava/lang/String;" is not applicable on this object)
我不明白这个错误是怎么回事。
这是代码
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();
我尝试了这三条路径,使用“/store”(在模拟器中运行时)获得输出,但其余两条路径出现错误。即使在设备中使用“/store”,也会显示相同的错误
Global.DB_PATH = "/MediaCard/databases/";
Global.DB_PATH = "/SDCard/databases/";
Global.DB_PATH = "/store/databases/";
有没有办法将SD卡/媒体卡作为根目录获取,以便复制其中的数据库?private ObjectListField getFileList(){
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;
}
if(fileList==null){
fileList=newObjectListField();
字符串[]根=新字符串[3];
枚举枚举=FileSystemRegistry.listRoots();
int x=0;
while(enum.hasMoreElements()){
if(x<3){
根[x]=enum.nextElement().toString();
}
x++;
}
enum=FileSystemRegistry.listRoots();
set((根[2]!=null)?根:新字符串[]{“system/”,“SDCard/”,“store/”});
}
返回文件列表;
}
试试这段代码。我的猜测是,当你在一台真正的设备上运行你的应用程序时,你已经将USB电缆插入了该设备。如果是这种情况,请尝试拔下电缆并重新运行应用程序。您可以使用
Dialog.inform()
快速检查您这次获得的根。我的问题是我没有获得文件根,即我没有获得根目录中的SD卡/或媒体卡,如代码所示。当我在设备中运行应用程序时,我只计算出一个根目录,即system/即使插入SD卡。(enum.hasMoreElements()只循环一次,给出root=system/)。是的,先生,您的猜测是对的,根据您的建议,我拔下了电缆,找到了SD卡的位置。我现在可以在SDCard中创建数据库。非常感谢。这只是BlackBerry..:(考虑创建一些记录器,将日志条目写入文件,然后你可以从设备下拉到PC进行调查。各位,在投票时也请说明理由。这样我就可以从这个案例中学习SMTH,这样下次就不会再犯同样的错误了。否则这只是一个幼稚/不诚实的行为。我总能接受我的错误。没有任何报复性反馈的kes。修复了我的问题:)我想这是因为它插入了USB驱动器。因此,该卡已连接到PC,无法通过电话访问。连接手机,以任何模式运行。然后手动从“我的电脑”中弹出存储驱动器。通过这种方式,您可以通过电缆连接,而不通过pc使用存储驱动器,因此可以运行调试模式。