姬長信(Redy)

Java错误:无法对非静态方法进行静态引用


我正在编写一个Android应用程序并收到此错误,但我不确定原因.有人可以帮我理解为什么我会收到这个错误吗?
Cannot make a static reference to the non-static method updateScores(List) from the type DatabaseHandler

这是相关的代码.

public class ScoreList extends SherlockFragmentActivity {
    List listScore = new ArrayList();
    public void updateListView() {
        listViewScore.setAdapter(new ScoreListAdapter(ctx,
                R.layout.score_row_item, listScore));
        DatabaseHandler.updateScores(listScore);    
    }
}

这是DatabaseHandler类.我尝试将函数设置为静态,但由于错误,它不会以这种方式工作.

public class DatabaseHandler extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "scoreKeeper";
    private static final String TABLE_GAMES = "games";    
    private static final String KEY_NAME = "name";
    private static final String KEY_CHANGE = "scoreChange";
    private static final String KEY_TOTAL = "scoreTotal";

    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_GAMES_TABLE = "CREATE TABLE " + TABLE_GAMES + "("
                + KEY_NAME + " INTEGER PRIMARY KEY," + KEY_CHANGE + " TEXT,"
                + KEY_TOTAL + " TEXT" + ")";
        db.execSQL(CREATE_GAMES_TABLE);
    }

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

    public void addScore(Score score) {
        SQLiteDatabase db = this.getWritableDatabase();    
        ContentValues values = new ContentValues();
        values.put(KEY_NAME, score.getName()); 
        values.put(KEY_CHANGE, score.getScoreChange());
        values.put(KEY_TOTAL, score.getScoreTotal());       

        // Inserting Row
        db.insert(TABLE_GAMES, null, values);
        db.close(); 
    }

    public List getAllScores() {
        List scoreList = new ArrayList();
        String selectQuery = "SELECT  * FROM " + TABLE_GAMES;

        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        if (cursor.moveToFirst()) {
            do {
                Score score = new Score("","","");
                score.setName(cursor.getString(0));
                score.setScoreChange(cursor.getString(1));
                score.setScoreTotal(cursor.getString(2));
                // Adding contact to list
                scoreList.add(score);
            } while (cursor.moveToNext());
        }

        return scoreList;       
    }

    public void updateScores(List score) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_GAMES);
        onCreate(db);

        ContentValues values = new ContentValues();
        for(int i = 0; i