我有一个android应用程序,使用游标返回一个表格的字符串值(所以我认为只有字符串)当我尝试解析int时,我得到了异常,所以我无法增加它,我只需要是每次调用它时从0到1,2,3,5,100,923021312等。
如果有人知道我错了怎么把它变成int或者如何直接把它从数据库中取出来作为int
public String dmst(String id_math)
{
String kleidi="";
int efedriko=0;
String parousies_max="0";
final String SQL_code = "SELECT "+DatabaseHelper.Col_PAROUSIES_MAX+" FROM "+DatabaseHelper.TABLE_NAME2+" WHERE "+DatabaseHelper.Col_ID_MATHIMA+" = "+id_math;
SQLiteDatabase sqLiteDatabase=this.getReadableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery(SQL_code,null);
if (cursor.moveToFirst()) {
do {
parousies_max = cursor.getString(cursor.getColumnIndex("PAROUSIES_MAX"));
}while (cursor.moveToNext());
}
cursor.close();
try {
efedriko = Integer.parseInt(parousies_max);
} catch(NumberFormatException nfe) {}
efedriko=efedriko+1;
答案 0 :(得分:0)
将do循环中的行从getString更改为getInt方法:
FROM:
parousies_max = cursor.getString(cursor.getColumnIndex(“PAROUSIES_MAX”));
TO:
parousies_max = cursor.getInt(cursor.getColumnIndex(“PAROUSIES_MAX”));