Android NullPointException on getWritableDatabase : <p>I know this question was asked a thousand times and I read a lot of them and the answers. But I couldnt fix my problem in this case.
When I'm calling the getWritableDatabase() Function in my android app I get this Exception:</p>

<pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
              Process: de.schneider_schwarz_inc.tagesablauf_log, PID: 12634
              java.lang.RuntimeException: Unable to start activity ComponentInfo{de.schneider_schwarz_inc.tagesablauf_log/de.schneider_schwarz_inc.tagesablauf_log.GUI.ToDo.ToDoList}: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.sqlite.SQLiteDatabase android.content.Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase$CursorFactory, android.database.DatabaseErrorHandler)' on a null object reference
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6077)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
               Caused by: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.sqlite.SQLiteDatabase android.content.Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase$CursorFactory, android.database.DatabaseErrorHandler)' on a null object reference
                  at de.schneider_schwarz_inc.tagesablauf_log.Database.ToDo.ToDoDao.insertToDo(ToDoDao.java:41)
                  at de.schneider_schwarz_inc.tagesablauf_log.Todo.createTodo(Todo.java:25)
                  at de.schneider_schwarz_inc.tagesablauf_log.GUI.ToDo.ToDoList.onCreate(ToDoList.java:47)
                  at android.app.Activity.performCreate(Activity.java:6664)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                  at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:154) 
                  at android.app.ActivityThread.main(ActivityThread.java:6077) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.sqlite.SQLiteDatabase android.content.Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase$CursorFactory, android.database.DatabaseErrorHandler)' on a null object reference
                  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
                  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
                  at de.schneider_schwarz_inc.tagesablauf_log.Database.ToDo.ToDoDao.insertToDo(ToDoDao.java:32)
                  at de.schneider_schwarz_inc.tagesablauf_log.Todo.createTodo(Todo.java:25) 
                  at de.schneider_schwarz_inc.tagesablauf_log.GUI.ToDo.ToDoList.onCreate(ToDoList.java:47) 
                  at android.app.Activity.performCreate(Activity.java:6664) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                  at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:154) 
                  at android.app.ActivityThread.main(ActivityThread.java:6077) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
</code></pre>

<p>My Sqliteopenhelper class:</p>

<pre><code>public ToDoDbHelper(Context context) {super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

public void onCreate(SQLiteDatabase db) {
    System.out.println("creating database");
    db.execSQL(SQL_CREATE_ENTRIES);
}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL(SQL_DELETE_ENTRIES);
    onCreate(db);
}

public static int getDatabaseVersion() {
    return DATABASE_VERSION;
}
</code></pre>

<p>I use it in this class:</p>

<pre><code>public class ToDoDao {
    private Context context;
    private ToDoDbHelper toDoDbHelper;

    public ToDoDao(Context context){
        this.context = context;
        toDoDbHelper = new ToDoDbHelper(context);
    }


/**
 * Inserts ToDos into Database
 * @param data data to insert
 * @return is -1 when error, else the id
 */
public long insertToDo(ToDoData data){
    try{
        SQLiteDatabase db = toDoDbHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(ToDoStructure.ToDoEntry.COLUMN_NAME_TITLE, data.getTitle());
        values.put(ToDoStructure.ToDoEntry.COLUMN_NAME_DATE, data.getDate());

        return db.insert(ToDoStructure.ToDoEntry.TABLE_NAME, null, values);
    }catch (Exception e){
        System.out.println("ERROR!");
        //TODO handling exception
        throw new RuntimeException(e);
    }
}
</code></pre>

<p>The Dao I use here:</p>

<pre><code>public class Todo {
private List&lt;ToDoData&gt; dataList;
private Context context;
private ToDoDao dao = new ToDoDao(context);

public Todo(Context context){
    this.context = context;
    //dataList = dao.getAllToDos();
    dataList = new ArrayList&lt;&gt;();
}

public int createTodo(String title, String date){
    ToDoData newData = new ToDoData(title, date);
    long id = dao.insertToDo(newData);
    if(id == -1){
        return (int) id;
    }
    newData.setId(String.valueOf(id));
    dataList.add(newData);
    return 0;
}
</code></pre>

<p>And at least my activity where I get my Context:</p>

<pre><code>public class ToDoList extends Activity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;

@Override
protected void onCreate(Bundle savedInstanceState){
    System.out.println("createListView");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_todo);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setHasFixedSize(true);

    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);


    Todo todo = new Todo(this);
    todo.createTodo("Test1", "20160910");
    List&lt;ToDoData&gt; todoList = todo.getDataList();
    System.out.println(todoList.get(0).getTitle());

    mAdapter = new ToDoViewAdapter(getBaseContext(), todoList);
    mRecyclerView.setAdapter(mAdapter);


}
</code></pre>

<p>I think the problem is my context. But I dont know to fix it...</p>

<p>Thanks!</p>
