【问题标题】:How to use sqlite database in Blackberry simulator?如何在黑莓模拟器中使用 sqlite 数据库?
【发布时间】:2013-05-17 09:25:19
【问题描述】:

您好,我是黑莓开发新手。

我正在尝试创建一个小型的 sqlite 演示应用程序。为此,我正在编写以下代码:

    try
    {
        URI myURI = URI.create("file:///SDCard/Databases/myDb.db"); 
        d = DatabaseFactory.openOrCreate(myURI);
        d.close();
        add(new RichTextField("DB created successfully"));
    }
    catch ( Exception e ) 
    {         
        System.out.println( e.getMessage() );
        e.printStackTrace();
        add(new RichTextField("Error: "+e.toString()));
    }

当我运行它时,我遇到了这样的异常

net.rim.device.api.database.DatabasePathException:路径名无效。路径不包含正确的根列表。有关详细信息,请参阅 FileSystemRegistry 类。

我已经在模拟器中设置了SD卡:Simulate-->change sdcard-->添加目录 (E:\mediacard)

【问题讨论】:

    标签: blackberry blackberry-simulator sqlite


    【解决方案1】:

    设置好SDCard后,在模拟器的文件浏览器中找到SDCard,检查是否安装正确。

    要了解使用 SQLite 数据库时的最佳实践,请查看http://docs.blackberry.com 中提供的 SQLite 示例应用程序。如果您使用 BlackBerry Plugins For Eclipse,那么您可以导入 SQLiteDemo 应用程序并检查代码。以下几行代码来自 SQLiteDemo 类的构造函数。

    // 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) {
        // no database can't be created
    }          
    else {
        // create database
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多