I'm have problem with adding a data to data base the edit text that I insert the data from is in second activity when I press add the app goes tosecond activity and when i try again the app crush.
HELP PLEASE!!!
this on sql data Healper class
public void onCreate(SQLiteDatabase db) {
String createTableStatement = "CREATE TABLE " + OPERATION_TABLE + " ("+" ID INTGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_OPERATION_NAME + " TEXT, " + COLUMN_OPERATION_AMOUNT + " TEXT, " + COLUMN_OPERATION_DESCRIPTION + " TEXT, " + COLUMN_OPERATION_IS_INCOME + " BOOL, " + COLUMN_DATE + " TEXT )";
db.execSQL(createTableStatement);
}
this a click listener in the activate:
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Operation operation;
try {
operation = new Operation(-1, nameOfOperation.getText().toString(), amount.getText().toString(), description.getText().toString(), income.isChecked(), dateOfOperation.getText().toString());
editTextClean();
Toast.makeText(InsertActivity.this, "the operation is saved " + operation.toString(), Toast.LENGTH_SHORT).show();
}catch (Exception e){
Toast.makeText(InsertActivity.this, "Error creating customer" , Toast.LENGTH_SHORT).show();
operation = new Operation(-1,"error", "error", "eror", true, "date error");
}
DataBaseHelper dataBaseHelper = new DataBaseHelper(InsertActivity.this);
boolean success =dataBaseHelper.addOne(operation);
Toast.makeText(InsertActivity.this, "Success= "+success, Toast.LENGTH_LONG).show();
}
});
and this the add method
public boolean addOne(Operation operation){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv =new ContentValues();
cv.put(COLUMN_OPERATION_NAME,operation.getName());
cv.put(COLUMN_DATE,operation.getDate());
cv.put(COLUMN_OPERATION_AMOUNT,operation.getAmount());
cv.put(COLUMN_OPERATION_DESCRIPTION,operation.getDescription());
cv.put(COLUMN_OPERATION_IS_INCOME,operation.isIncome());
long insert = db.insert(OPERATION_TABLE, null, cv);
if(insert ==-1){
return false;
}else {
return true;
}
}