jeudi 7 janvier 2016

Android studio attempt to invoke virtual method on a null object reference SQLite [duplicate]

This question already has an answer here:

hey guys new to java and android studio and I'm getting an error trying to add data to an sqlite database, I'm getting null object reference on these functions. Any help would be appreciated :) main.class

public void addDataButtonPressed(View view){
            String no=birthyear.getText().toString();       //this will get a string
            int no2=Integer.parseInt(no);               //converts it to an integer
            dbHandler.insertStudent(firstname.getText().toString(), lastname.getText().toString(), gender.getText().toString(), no2); //messy ):
        }

dbhelper.class

public boolean insertStudent(String firstname, String lastname, String gender, int birthyear) {
        SQLiteDatabase db = getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(COLUMN_FIRSTNAME, firstname);
        contentValues.put(COLUMN_LASTNAME, lastname);
        contentValues.put(COLUMN_GENDER, gender);
        contentValues.put(COLUMN_YEAROFBIRTH, birthyear);
        db.insert(TABLE_STUDENTINFO, null, contentValues);
        return true;
    }

Aucun commentaire:

Enregistrer un commentaire