2013-01-25 2 views
0

이 코드 줄에 문제가있어서 getInt 메서드에서 컴파일러 오류가 발생했습니다. 변수 KEY_HITS가 String이 아니고 int가 아니기 때문입니다. 이 문제를 어떻게 수정합니까?android에서 sqlite 데이터베이스의 컴파일러 오류를 해결하는 방법

total = total + c.getInt(KEY_HITS); 

여기 코드가 더 있습니다.

public static final String KEY_ROWID="_id"; 
    public static final String KEY_NAME="persons_name"; 
    public static final String KEY_HITS="persons_hits"; 

public int getTotal() { 

String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_HITS }; 
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, 
     null, null); 
int total = 0; 

for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { 
    total = total + c.getInt(KEY_HITS); 
} 
return total; 
} 

답변

1

변수 KEY_HITS이 String의 아닌 INT
당신이 getInt()에서 정수 매개 변수를 전달해야하기 때문에 을 말하는 오류 않습니다. 열의 색인을 얻을 수 있습니다. getColumnIndex()

total = total + c.getInt(c.getColumnIndex(KEY_HITS)); 
+0

감사합니다.이 기능은 완벽하게 작동합니다. – Kevik

관련 문제