title: Android - open SQLite database
body: <p>I would like to open a database and get data from it. I read a tutorial about this and made an application. I'm trying to check if the database exists, if not, create a new db in the Android's default system path of your application database and copy the data from a db to there (which is in the assets folder). But when I'm running the application I got the error:</p>
  
  <pre><code>SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase$CursorFactory, String, String[], String) line: 1568   
  </code></pre>
  
  <p>Can somebody give me some advice about what i made wrong? Here is the code:</p>
  
  <pre><code>package thesis.app.quiz;
  
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.ArrayList;
  import java.util.List;
  
  import android.content.Context;
  import android.database.Cursor;
  import android.database.SQLException;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  public class DBHelperForQuiz extends SQLiteOpenHelper {
  
      //The Android's default system path of your application database.
      private static String DB_PATH = "/data/data/thesis.app.quiz/databases/";
      private static String DB_NAME = "QuizDB";
      private SQLiteDatabase myDataBase;
      private final Context myContext;
  
      public DBHelperForQuiz(Context context) {
          super(context, DB_NAME, null, 1);
          this.myContext = context;
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
  
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
      }
  
      public void openDataBase() {
  
  
          String myDbPath = DB_PATH + DB_NAME;
          myDataBase = SQLiteDatabase.openDatabase(myDbPath, null,
                  SQLiteDatabase.OPEN_READONLY);
      }
  
      @Override
      public synchronized void close() {
          if (myDataBase != null)
              myDataBase.close();
          super.close();
      }
  
      public List&lt;Question&gt; getQuestionsList(int difficulty, int numberOfQuestions) {
  
  
  
          List&lt;Question&gt; questionsList = new ArrayList&lt;Question&gt;();
  
          Cursor c = myDataBase.rawQuery("SELECT * FROM questions", null);
  
          while (c.moveToNext()) {
              Question q = new Question();
              q.setQuestionText(c.getString(1));
              q.setRightAnswer(c.getString(2));
              q.setAnswerOption1(c.getString(3));
              q.setAnswerOption2(c.getString(4));
              q.setAnswerOption3(c.getString(5));
              q.setQuestionDiffLevel(difficulty);
              questionsList.add(q);
          }
  
          return questionsList;
  
      }
  
      public void createDataBase() throws IOException {
  
          if (!checkIfDBAlredyExist()) {
  
              this.getReadableDatabase(); 
  
              try {
                  InputStream myInput = myContext.getAssets().open(DB_NAME);
  
                  String newDbPath = DB_PATH + DB_NAME; 
                  OutputStream myOutput = new FileOutputStream(newDbPath);
  
                  byte[] buffer = new byte[1024];
                  int length;
                  while ((length = myInput.read(buffer)) &gt; 0) {
                      myOutput.write(buffer, 0, length);
                  }
  
                  myOutput.flush();
                  myOutput.close();
                  myInput.close();
  
              } catch (IOException e) {
  
                  e.printStackTrace();
                  throw new Error("Error copying database");
              }
  
          }
  
      }
  
      public boolean checkIfDBAlredyExist() {
  
  
          SQLiteDatabase tmpDb = null;
          String dbPath = DB_PATH + DB_NAME;
          try {
              tmpDb = SQLiteDatabase.openDatabase(dbPath, null,
                      SQLiteDatabase.OPEN_READONLY);
          } catch (SQLException e) {
              e.printStackTrace();
          }
  
          if (tmpDb != null) {
              tmpDb.close();
              //return true;
          }
  
          return tmpDb != null ? true : false;
      }
  }
  </code></pre>