Q:

Android app crashes on clicking button to send a textview to SQL litein emulator

The code I have developed was in Android Studio.
I am currently trying to make an app that upon clicking a button it will send the text in a textview to a database created via SQLite. However upon clicking the button the the app is crashing on the emulator.
The following Exception is being thrown:
04-22 21:20:48.325 7661-7661/com.example.chris.mindyourmood 
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.chris.mindyourmood, PID: 7661
java.lang.IllegalStateException: Could not execute method for 
android:onClick
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
    at android.view.View.performClick(View.java:6294)
    at android.view.View$PerformClick.run(View.java:24770)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
    at android.view.View.performClick(View.java:6294) 
    at android.view.View$PerformClick.run(View.java:24770) 
    at android.os.Handler.handleCallback(Handler.java:790) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6494) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.chris.mindyourmood.MyMoodDatabaseHelper.addMoods(com.example.chris.mindyourmood.Moods)' on a null object reference
    at com.example.chris.mindyourmood.MainActivity.EsctaticClicked(MainActivity.java:61)
    at java.lang.reflect.Method.invoke(Native Method) 
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
    at android.view.View.performClick(View.java:6294) 
    at android.view.View$PerformClick.run(View.java:24770) 
    at android.os.Handler.handleCallback(Handler.java:790) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6494) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

Below is the code for my main activity: 
public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

Toolbar toolbar=null;
EditText editText;
TextView txtEcstatic, txtHappy, txtFine, txtSad, txtAngry;
MyMoodDatabaseHelper databaseHelper;
Button logButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //Navigation drawer code
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    //identify the textviews
    txtEcstatic = findViewById(R.id.Ecstatic);
    txtHappy = findViewById(R.id.Happy);
    txtFine = findViewById(R.id.Fine);
    txtSad = findViewById(R.id.Sad);
    txtAngry = findViewById(R.id.Angry);

 //   databaseHelper = new MyMoodDatabaseHelper(this, null, null, 1);
}

//Add to Database methods
public void EsctaticClicked(View view){
    Moods moods = new Moods(txtEcstatic.getText().toString());
    databaseHelper.addMoods(moods);
    Toast.makeText(this,"Ecstatic mood logged", Toast.LENGTH_LONG);
}

public void HappyClicked(View view){
    Moods moods = new Moods(txtHappy.getText().toString());
    databaseHelper.addMoods(moods);
    Toast.makeText(this,"Happy mood logged", Toast.LENGTH_LONG);
}

public void FineClicked(View view){
    Moods moods = new Moods(txtFine.getText().toString());
    databaseHelper.addMoods(moods);
    Toast.makeText(this,"Fine mood logged", Toast.LENGTH_LONG);
}

public void SadClicked(View view){
    Moods moods = new Moods(txtSad.getText().toString());
    databaseHelper.addMoods(moods);
    Toast.makeText(this,"Sad mood logged", Toast.LENGTH_LONG);
}

public void AngryClicked(View view){
    Moods moods = new Moods(txtAngry.getText().toString());
    databaseHelper.addMoods(moods);
    Toast.makeText(this,"Angry mood logged", Toast.LENGTH_LONG);
}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id=item.getItemId();
    switch (id) {

        case R.id.nav_MainActivity:
            Intent log = new Intent(MainActivity.this, MainActivity.class);
            startActivity(log);
            break;
        case R.id.nav_map:
            Intent maps = new Intent(MainActivity.this, Map.class);
            startActivity(maps);
            break;
        case R.id.nav_history:
            Intent hist = new Intent(MainActivity.this, History.class);
            startActivity(hist);
            break;
        case R.id.nav_settings:
            Intent set = new Intent(MainActivity.this, Settings.class);
            startActivity(set);
        case R.id.nav_about:
            Intent abt = new Intent(MainActivity.this, About.class);
            startActivity(abt);
        case R.id.nav_contact:
            Intent cont = new Intent(MainActivity.this, Contact.class);
            startActivity(cont);
            break;
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

}
And this finally is the code for for my Database Helper:
public class MyMoodDatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "moods.db";
public static final String TABLE_MOODS = "Moods";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_MOODNAME = "Mood Name";

public MyMoodDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, DATABASE_NAME, null, 1);
    SQLiteDatabase db = this.getWritableDatabase();
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
    SQLiteDatabase db = this.getWritableDatabase();
    String query = "CREATE TABLE " + TABLE_MOODS + " ( " + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMN_MOODNAME + ", TEXT " + ");";
    db.execSQL(query);
}

public void addMoods (Moods moods){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COLUMN_MOODNAME,moods.get_moodname());
    db.insert(TABLE_MOODS,null,values);//insert a new row
    db.close();//close database connection

}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

}

public String databasetostring(){
    String dbstring="";
    SQLiteDatabase db = getWritableDatabase();

    String query= "SELECT * FROM " + TABLE_MOODS +" WHERE 1";

    Cursor c = db.rawQuery(query, null);
    c.moveToFirst();

    while(!c.isAfterLast()){
        if(c.getString(c.getColumnIndex("moodname"))!=null){
            dbstring += c.getString(c.getColumnIndex("moodname"));
            dbstring += "\n";
        }
        c.moveToNext();
    }
    db.close();
    return dbstring;
}

}

A:

Uncomment this line :
//   databaseHelper = new MyMoodDatabaseHelper(this, null, null, 1);
You have not initialised your databaseHelper instance variable.

