title: getWritableDatabase closing my program
body: <p>I just recently started working on a project but my program repeatedly crashes. I think it is due to getWritableDatabase. I was following a tutorial and i did everything they told me to, i even checked over my code multiple times. If u are interested in the link to the tutorial, it is <a href="https://www.youtube.com/watch?v=38DOncHIazs" rel="nofollow">https://www.youtube.com/watch?v=38DOncHIazs</a></p>
  
  <pre><code>public class AddExpense extends Activity {
  
  EditText inputDate , inputDescription, inputCategory, inputAmount;
  Context context;
  UserDbHelper userDbHelper;
  SQLiteDatabase sqLiteDatabase;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_add_expense);
      inputDate = (EditText) findViewById(R.id.inputDate);
      inputDescription = (EditText) findViewById(R.id.inputDescription);
      inputCategory = (EditText) findViewById(R.id.inputCategory);
      inputAmount = (EditText) findViewById(R.id.inputAmount);
  
  }
  
  public void AddExpense(View view){
      String date = inputDate.getText().toString();
      String description = inputDescription.getText().toString();
      String category = inputCategory.getText().toString();
      String amount = inputAmount.getText().toString();
      userDbHelper = new UserDbHelper(context);
      sqLiteDatabase = userDbHelper.getWritableDatabase();
      userDbHelper.addInformations(date, description, category, amount, sqLiteDatabase);
      Toast.makeText(getBaseContext(),"Data Saved", Toast.LENGTH_LONG).show();
      userDbHelper.close();
  }
  
  }
  </code></pre>
  
  <p>And this is my database helper class</p>
  
  <pre><code>public class UserDbHelper extends SQLiteOpenHelper {
  
  private static final String DATABASE_NAME = "EXPENSE.DB";
  private static final int DATABASE_VERSION = 1;
  private static final String CREATE_QUERY =
          "CREATE TABLE " + ExpenseDatabase.NewExpenseItem.TABLE_NAME + " ("+ ExpenseDatabase.NewExpenseItem.DATE+" TEXT,"+ ExpenseDatabase.NewExpenseItem.DESCRIPTION+ " TEXT,"+
          ExpenseDatabase.NewExpenseItem.CATEGORY+" TEXT," + ExpenseDatabase.NewExpenseItem.AMOUNT+ " TEXT);";
  
  public UserDbHelper(Context context){
  
  
      super(context,DATABASE_NAME,null,DATABASE_VERSION);
      Log.e("DATABASE OPERATIONS", "Database created / opened");
  }
  @Override
  public void onCreate(SQLiteDatabase db) {
  
      db.execSQL(CREATE_QUERY);
      Log.e("DATABASE OPERATIONS", "Table created");
  
  }
  
  public void addInformations(String date, String description, String category, String amount,SQLiteDatabase db ){
      ContentValues contentValues = new ContentValues();
      contentValues.put(ExpenseDatabase.NewExpenseItem.DATE,date);
      contentValues.put(ExpenseDatabase.NewExpenseItem.DESCRIPTION, description);
      contentValues.put(ExpenseDatabase.NewExpenseItem.CATEGORY, category);
      contentValues.put(ExpenseDatabase.NewExpenseItem.AMOUNT, amount);
      db.insert(ExpenseDatabase.NewExpenseItem.TABLE_NAME, null, contentValues);
      Log.e("DATABASE OPERATIONS", "One row inserted in DB");
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
  }
  }
  </code></pre>