0

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;
        }
    }
  • 1
    In your `onCreate` method `INTEGER` is spelled wrong. If your app is crashing you need to look at the logs from Logcat and include them in your question so people can help you with why it is crashing. – David Conrad Jun 27 '22 at 20:18
  • Also you need to [properly log the exception](https://stackoverflow.com/a/4341391/636009) in your OnClickListener (and anywhere else you are catching exceptions) in order to get useful information from [Logcat](https://developer.android.com/studio/debug/am-logcat). – David Conrad Jun 27 '22 at 20:23
  • 1
    @DavidConrad you solved me problem it was just typo problem I am going to write INTEGER 100-times to practices writing it :) – Abdulhadi Heib Jun 27 '22 at 20:39
  • I'm glad I was able to help. Remember to always double check everything, even when you feel sure you got it right. That's the hardest time to see that you typed it wrong. – David Conrad Jun 27 '22 at 20:46

0 Answers0