无法从我的DatabaseHelper文件中解析方法“ insertData”

这是我的dbHelper代码

    public class DatabaseHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "URC.db";
    public static final String TABLE_NAME = "thoughLog";
    public static final String COL_1 = "ID";
    public static final String COL_2 = "URGE";
    public static final String COL_3 = "CONTRADICTIONS";
    public static final String COL_4 = "RESPONSE";

        public DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, 1);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT,URGE TEXT,CONTRADICTIONS TEXT,RESPONSE TEXT)");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
            onCreate(db);
        }

        public boolean insertData(String urge, String contradictions, String response) {
            SQLiteDatabase db = this.getWritableDatabase();
            ContentValues contentValues = new ContentValues();
            contentValues.put(COL_2, urge);
            contentValues.put(COL_3, contradictions);
            contentValues.put(COL_4, response);
            long result = db.insert(TABLE_NAME, null, contentValues);
            if (result == -1)
                return false;
            else
                return true;
    }

然后我的主要活动代码是

public class MainActivity<DatabaseHelper> extends AppCompatActivity {

    DatabaseHelper myDb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myDb = new DatabaseHelper(this);
        EditText urgtextedit = (EditText) findViewById(R.id.urgtextedit);
        EditText contextedit = (EditText) findViewById(R.id.contextedit);
        EditText restextedit = (EditText) findViewById(R.id.restextedit);
        Button savebutton = (Button) findViewById(R.id.savebutton);

        public void AddData AddData();
            savebutton.setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            boolean isInserted = myDb.insertData(urgtextedit.getText().toString(),
                                    contextedit.getText().toString(),
                                    restextedit.getText().toString());
                        }
                    }
            );
    }
}

我是android studio和java的新手,我不知道为什么insertData是红色的,并带有错误无法从我的DatabaseHelper中解析方法“ insertData”,我认为问题出在我的主要活动代码上,但我不确定

评论