2017-04-21 84 views
-4

我在获取NullpointerException时尝试访问Assets文件夹中的db。在Assets文件夹中,db显示为红色。在资产文件夹中打开sqlite数据库时出错

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(); 
} 

有没有什么办法来检查字符串的分贝值?

+0

发布您的代码从资产 –

+0

越来越分贝但代码停在myinput显示NullPointerException异常 –

+0

的你得到的是不要让分贝 –

回答

0

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

你为什么没有告诉数值的任何原因?

+0

你是如何得出这个结论的?这会抛出'FileNotFoundException',而不是'NullPointerException'。我的意思是,我不是说你错了。他们很可能有错误的名字,但显然,直接的问题是NPE。我错过了一些意见吗? –

+0

那么请告诉DB_NAME的值。和文件名。比较。他们不平等。如果我建议他们不平等,为什么你不发布两个值?而且我甚至要求你讲述价值。难以置信的。 – greenapps

+0

我不是OP。我只是问他们是否提到了'DB_NAME'的价值,因为我错过了一些已被删除的评论。 –

相关问题