Android アプリを作成していて、このエラーが発生していますが、その理由がわかりません。このエラーが発生する理由を誰かが理解するのを手伝ってくれますか?
Cannot make a static reference to the non-static method updateScores(List<Score>) from the type DatabaseHandler
関連するコードは次のとおりです。
public class ScoreList extends SherlockFragmentActivity {
List<Score> listScore = new ArrayList<Score>();
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<Score> getAllScores() {
List<Score> scoreList = new ArrayList<Score>();
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> score) {
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DROP TABLE IF EXISTS " + TABLE_GAMES);
onCreate(db);
ContentValues values = new ContentValues();
for(int i = 0; i < score.size(); i++){
values.put(KEY_NAME, score.get(i).getName());
values.put(KEY_CHANGE, score.get(i).getScoreChange());
values.put(KEY_TOTAL, score.get(i).getScoreTotal());
}
}
}