title: Why can't my Android app see the database file?
body: <p>I'm creating an Android app, and I want to make a registration. I have already written the file where is C.R.U.D to database. When I start my app and try to add somebody, I can see the popup with the message:</p>
  
  <pre><code>"Unfortunately , the application has been stopped". 
  </code></pre>
  
  <p>Here is my database controller code:</p>
  
  <pre><code>package com.example.lingwista.lingwista;
  
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  public class DB_Controller extends SQLiteOpenHelper {
  public DB_Controller(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
      super(context, "LINGWISTA.db", factory, version);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE USERS( ID INTEGER PRIMARY KEY AUTOINCREMENT, USERNAME TEXT UNIQUE, PASSWORD TEXT);");
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS USERS;");
  }
  
  public void insert_user(String userName, String password){
      ContentValues contentValues = new ContentValues();
      contentValues.put("USERNAME",userName);
      contentValues.put("PASSWORD",password);
      this.getWritableDatabase().insertOrThrow("USERS", "", contentValues);
  }
  
  
  public boolean search_user(String userName){
      Cursor cursor = this.getReadableDatabase().rawQuery("SELECT USERNAME FROM USERS",null);
      while (cursor.moveToNext()){
          if(cursor.getString(1).equals(userName)){
              return true;
          }
      }
      return false;
  }
  
  public boolean search_password(String password){
      Cursor cursor = this.getReadableDatabase().rawQuery("SELECT PASSWORD FROM USERS",null);
      while (cursor.moveToNext()){
          if(cursor.getString(1).equals(password)){
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is the java file where I use the controller:</p>
  
  <pre><code>package com.example.lingwista.lingwista;
  
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class Rejestracja extends AppCompatActivity {
  DB_Controller controller;
  EditText username;
  EditText password1;
  EditText password2;
  String login;
  String haslo1;
  String haslo2;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_rejestracja);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      username = (EditText)findViewById(R.id.editText3);
      password1 = (EditText)findViewById(R.id.editText4);
      password2 = (EditText)findViewById(R.id.editText5);
      controller = new DB_Controller(this, "", null, 1);
  }
  
  public void goToMenu(View view) {
      login = username.getText().toString();
      haslo1 = password1.getText().toString();
      haslo2 = password2.getText().toString();
  
      boolean u;
  
      String message;
      Context context = getApplicationContext();
      int duration = Toast.LENGTH_SHORT;
  
      if(haslo1.equals(haslo2)){
          u = controller.search_user(login);
  
          if(u==true){
              message = "Istnieje już użytkownik który korzysta z tego adresu email";
              Toast toast = Toast.makeText(context,message, duration);
              toast.show();
          }
          else{
              controller.insert_user(login,haslo1);
              Intent intent = new Intent(".Menu");
              startActivity(intent);
          }
  
  
      }else{
          message = "Błąd hasła. Proszę upewnić się ze oba pola zawierają to samo hasło";
          Toast toast = Toast.makeText(context,message, duration);
          toast.show();
      }
      if(login.equals("") || haslo1.equals("") || haslo2.equals("")){
          message = "Wszystkie pola muszą być wypełnione !";
          Toast toast = Toast.makeText(context,message, duration);
          toast.show();
      }
  }
  
  @Override
  public void onPause(){
      super.onPause();
      finish();
  }
  
  public void back(View view) {
      Intent intent =new Intent(".MainMenuActivity");
      startActivity(intent);
  }
  
  public void exitApp(View view) {
      System.exit(0);
  }
  }
  </code></pre>
  
  <p>And this is my content.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  app:layout_behavior="@string/appbar_scrolling_view_behavior"
  tools:context="com.example.lingwista.lingwista.Rejestracja"
  tools:showIn="@layout/activity_rejestracja"&gt;
  
  &lt;ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageView2"
      android:layout_alignParentTop="true"
      android:src="@drawable/lingwista"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:text="Rejestracja"
      android:id="@+id/textView3"
      android:layout_below="@+id/imageView2"
      android:layout_centerHorizontal="true"
      android:textColor="#00FF00"
      android:layout_marginTop="30dp"
      android:textSize="38dp" /&gt;
  
  &lt;EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:inputType="textEmailAddress"
      android:ems="10"
      android:id="@+id/editText3"
      android:layout_below="@+id/textView3"
      android:layout_marginTop="10dp"
      android:layout_centerHorizontal="true"
      android:autoText="false"
      android:hint="Adres email"
      android:backgroundTint="#0000ff" /&gt;
  
  &lt;EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:inputType="textPassword"
      android:ems="10"
      android:id="@+id/editText4"
      android:layout_below="@+id/editText3"
      android:layout_marginTop="5dp"
      android:layout_centerHorizontal="true"
      android:hint="Hasło"
      android:backgroundTint="#0000ff" /&gt;
  
  &lt;EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:inputType="textPassword"
      android:ems="10"
      android:id="@+id/editText5"
      android:layout_below="@+id/editText4"
      android:layout_alignRight="@+id/editText4"
      android:layout_marginTop="5dp"
      android:layout_alignEnd="@+id/editText4"
      android:hint="Powtorz hasło"
      android:backgroundTint="#0000ff" /&gt;
  
  &lt;Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Zarejestruj"
      android:id="@+id/button12"
      android:layout_marginTop="52dp"
      android:layout_below="@+id/editText5"
      android:layout_centerHorizontal="true"
      android:textColor="#ffffff"
      android:textSize="20dp"
      android:background="#0000ff"
      android:onClick="goToMenu"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This is the error log:</p>
  
  <pre><code>01-16 02:55:10.539 18767-18791/com.example.lingwista.lingwista E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab855e50
  01-16 02:55:13.104 18767-18767/com.example.lingwista.lingwista E/CursorWindow: Failed to read row 0, column 1 from a CursorWindow which has 1 rows, 1 columns.
  01-16 02:55:13.104 18767-18767/com.example.lingwista.lingwista D/AndroidRuntime: Shutting down VM
  01-16 02:55:13.104 18767-18767/com.example.lingwista.lingwista E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.lingwista.lingwista, PID: 18767
  java.lang.IllegalStateException: Could not execute method for android:onClick
   at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275)
   at android.view.View.performClick(View.java:5198)
   at android.view.View$PerformClick.run(View.java:21147)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:148)
   at android.app.ActivityThread.main(ActivityThread.java:5417)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  Caused by: java.lang.reflect.InvocationTargetException
   at java.lang.reflect.Method.invoke(Native Method)
   at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
   at android.view.View.performClick(View.java:5198) 
   at android.view.View$PerformClick.run(View.java:21147) 
   at android.os.Handler.handleCallback(Handler.java:739) 
   at android.os.Handler.dispatchMessage(Handler.java:95) 
   at android.os.Looper.loop(Looper.java:148) 
   at android.app.ActivityThread.main(ActivityThread.java:5417) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
   at android.database.CursorWindow.nativeGetString(Native Method)
   at android.database.CursorWindow.getString(CursorWindow.java:438)
   at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
   at com.example.lingwista.lingwista.DB_Controller.search_user(DB_Controller.java:35)
   at com.example.lingwista.lingwista.Rejestracja.goToMenu(Rejestracja.java:47)
   at java.lang.reflect.Method.invoke(Native Method) 
   at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270) 
   at android.view.View.performClick(View.java:5198) 
   at android.view.View$PerformClick.run(View.java:21147) 
   at android.os.Handler.handleCallback(Handler.java:739) 
   at android.os.Handler.dispatchMessage(Handler.java:95) 
   at android.os.Looper.loop(Looper.java:148) 
   at android.app.ActivityThread.main(ActivityThread.java:5417) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  01-16 02:55:19.507 18767-18767/? I/Process: Sending signal. PID: 18767 SIG: 9
  </code></pre>