正如@ItachiUchiha指出的,您的问题与您尝试创建数据库的位置有关:
String dbUrl = "jdbc:sqlite:" + dbName;Connection conn = DriverManager.getConnection(dbUrl);
您提供的URL可能在您的桌面上工作,但不能在移动设备上工作,在该设备上,该应用对存储的访问非常受限,并且仅授予对私有本地存储的访问权限。
使用Gluon的开源库Charm-Down,无论运行该应用程序的平台如何,都非常容易获得该本地存储的路径。
首先,将以下依赖项添加到
build.gradle脚本中:
ext.CHARM_DOWN_VERSION = "1.0.0"dependencies { compile "com.gluonhq:charm-down-common:$CHARM_DOWN_VERSION" desktopRuntime "com.gluonhq:charm-down-desktop:$CHARM_DOWN_VERSION" androidRuntime "com.gluonhq:charm-down-android:$CHARM_DOWN_VERSION" iosRuntime "com.gluonhq:charm-down-ios:$CHARM_DOWN_VERSION"}现在,在您的代码上,URL应该是:
try { File dir = PlatformFactory.getPlatform().getPrivateStorage(); File db = new File (dir, dbName); String dbUrl = "jdbc:sqlite:" + db.getAbsolutePath(); Connection conn = DriverManager.getConnection(dbUrl); ...} catch (Exception e) { }


