2017-04-21 120 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'的價值,因爲我錯過了一些已被刪除的評論。 –

相關問題