This is my activity class.when i press the data button data should be inserted into database.But every time "Not inserted" comes up
my = new DatabaseHandler(this);
data=(Button)findViewById(R.id.data);
data.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
time=clockTimeTextView.getText().toString();
repeat=Repeat_optionTextview.getText().toString();
ringtone=Ringtone_optionTextview.getText().toString();
if(chkBox.isChecked()){
vibrate="true";
}else{
vibrate="false";
}
method=Method_optionTextview.getText().toString();
//Toast.makeText(getApplicationContext(),method + ringtone ,Toast.LENGTH_LONG).show();
boolean checkers = my.addtotable(et.getText().toString(),time,repeat,ringtone,vibrate,method);
if (checkers == true) {
Toast.makeText(AddAlarmActivity.this, "Successfully Inserted", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(AddAlarmActivity.this, "Not Inserted", Toast.LENGTH_LONG).show();
}
}
});
This is the DatabaseHandler class
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHandler extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "database5.db";
private static final String TABLE_NAME = "mytable10";
private static final String COLUMN1 = "ID";
private static final String COLUMN2 = "TIME";
private static final String COLUMN3 = "REPEAT";
private static final String COLUMN4 = "RINGTONE";
private static final String COLUMN5 = "VIBRATE";
private static final String COLUMN6 = "METHOD";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, 2);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query;
query = "CREATE TABLE " + TABLE_NAME + "(" + COLUMN1 + " INTEGER PRIMARY KEY , "
+ COLUMN2 + " TEXT , "
+ COLUMN3 + " TEXT , "
+ COLUMN4 + " TEXT , "
+ COLUMN5 + " TEXT , "
+ COLUMN6 + "TEXT " + ")";
db.execSQL(query);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(" DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public boolean addtotable(String id, String time, String repeat, String ringtone,String vibrate,String method) {
SQLiteDatabase sqLiteDatabase = getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN1, id);
contentValues.put(COLUMN2, time);
contentValues.put(COLUMN3, repeat);
contentValues.put(COLUMN4, ringtone);
contentValues.put(COLUMN5, vibrate);
contentValues.put(COLUMN6, method);
long checker = sqLiteDatabase.insert(TABLE_NAME, null, contentValues);
if (checker == -1) {
return false;
} else {
return true;
}
}
public Cursor display() {
SQLiteDatabase sqLiteDatabase = getReadableDatabase();
Cursor res;
res = sqLiteDatabase.rawQuery("SELECT * FROM " + TABLE_NAME, null);
return res;
}
}
when i make two column(column_1 & column_2) it works fine.But i when i make more than two column "Not Inserted" message comes.i can't find where the error is.help please