当我将数据库复制到 FileSystemStorage 时,为什么会出现 NullPointerException?

问题描述 投票:0回答:1

我已使用代码示例将包含的数据库复制到 FileSystemStorage 中。数据库被复制了,但是Util.copy(pi, po);行抛出 NullPointerException。有人有主意吗?谢谢。

       String pathp = Display.getInstance().getDatabasePath("players.db").toString();
       if(pathp != null && !FileSystemStorage.getInstance().exists(pathp)) {
           try(InputStream pi = Display.getInstance().getResourceAsStream(getClass(), "/players.db");
               OutputStream po = FileSystemStorage.getInstance().openOutputStream(pathp)) {
               Util.copy(pi, po);
               Util.cleanup(po);
               Util.cleanup(pi);
           } catch(IOException err) {
               Log.e(err);
           }
       }
codenameone
1个回答
0
投票

我想您需要将您的应用程序与您已有的数据库一起发布。如果是这种情况,这条线

Display.getInstance().getResourceAsStream(getClass(), "/players.db");

预计您的项目在

players.db
目录中(如果是 Maven 构建)或
resources
目录中(如果是 ant 构建)有
src
文件

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.