在assets文件夹中打开sqlite db时出错

时间:2017-04-21 05:17:29

标签: android sqlite nullpointerexception

我在尝试访问NullpointerException文件夹中的db时收到Assetsdb文件夹中Assets的颜色显示为红色。

Image containing Db in Assets

public void createdatabase() throws IOException
{
    System.out.println(" came into Create database ");
    //Open your local db as the input stream
    InputStream myinput = mycontext.getAssets().open(DB_NAME);
    System.out.println(" myinput = "+myinput.toString());
    System.out.println(" Got input ");

    // Path to the just created empty db
    String outfilename = DB_PATH + DB_NAME;
    System.out.println(" outfilename = "+outfilename);

    //Open the empty db as the output stream
    OutputStream myoutput = new FileOutputStream(outfilename);

    // transfer byte to inputfile to outputfile
    System.out.println(" created outputStream");
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myinput.read(buffer))>0) {
        myoutput.write(buffer,0,length);
    }

    //Close the streams
    myoutput.flush();
    myoutput.close();
    myinput.close();
}

有没有办法检查String中的db值?

1 个答案:

答案 0 :(得分:0)

DB_NAME与资产文件夹中文件的名称不匹配。

你没有说出价值的任何理由?