In the main activity I create database
class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "myDB", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table mytable ("
+ "id integer primary key autoincrement,"
+ "name text,"
+ "obId text,"
+ "latit text,"
+ "long text" + ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
In the second activity I call the class of database
MainActivity myActivity = new MainActivity();
dbHelper = myActivity.new DBHelper(myActivity);
And insert data
ContentValues cv = new ContentValues();
db = openOrCreateDatabase("myDB.db", SQLiteDatabase.OPEN_READWRITE, null);
cv.put("name", textViewName.getText().toString());
long rowID = db.insert("mytable", null, cv);
db.insert("mytable", null, cv);
dbHelper.close();
The output "rowID" is "-1". I do not understand why this is happening