title: How to fix getWritableDatabase() error in android studio?
body: <p>I'm using <code>SQLite</code> for the first time. I'm following some youtube tutorial for this. But I'm facing error with <code>getWritableDatabase()</code>. </p>
  
  <pre><code>SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();
  </code></pre>
  
  <p>if I add this line in <code>Mainactivity.java</code>, my app keeps stopping. If I remove this line, then my app runs but the database doesn't create.</p>
  
  <p>How can I solve this problem? Thanks in advance.</p>
  
  <p>This is my Database class:</p>
  
  <pre><code>public class DatabaseHelper extends SQLiteOpenHelper {
  
  
      private static final String DATABASE_NAME = "attendanceproject.db";
      private static final String TABLE_NAME = "TeacherInfo";
      private static final String ID = "_id";
      private static final String NAME ="name";
      private static final String EMAIL = "email";
      private static final String PASSWORD = "password";
      private static final String PHONE = "phone";
      private static final int VERSION_NAME = 3;
      private static final String CREATE_TABLE = "CREATE TABLE "+TABLE_NAME+"("+ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+NAME+" VARCHAR(100) NOT NULL,"+EMAIL+" TEXT NOT NULL, "+PASSWORD+" TEXT NOT NULL, "+PHONE+" VARCHAR(11) NOT NULL);";
      private static final String DROP_TABLE = "DROP TABLE IF EXISTS "+TABLE_NAME;
      private Context context;
  
      public DatabaseHelper(@Nullable Context context) {
          super(context, DATABASE_NAME, null, VERSION_NAME);
  
      }
  
      @Override
      public void onCreate(SQLiteDatabase sqLiteDatabase) {
          try {
  
              sqLiteDatabase.execSQL(CREATE_TABLE);
              Toast.makeText(context, "Oncreate is Called", Toast.LENGTH_SHORT).show();
  
          } catch (Exception e) {
  
              Toast.makeText(context, "Exception" + e, Toast.LENGTH_SHORT).show();
  
          }
  
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
  
      }
  }
  </code></pre>
  
  <p>error: 
  <a href="https://i.stack.imgur.com/FR6Pi.png" rel="nofollow noreferrer">enter image description here</a></p>