如何在 Android 中递增数字字符串值
how to increment numeric string value in Android
我有一个 android 应用程序,它 returns 一个字符串值形成一个 table 使用游标(所以我认为只有字符串),当我尝试解析 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;
将 do 循环中的行从 getString 方法更改为 getInt 方法:
发件人:
parousies_max = cursor.getString(cursor.getColumnIndex("PAROUSIES_MAX"));
收件人:
parousies_max = cursor.getInt(cursor.getColumnIndex("PAROUSIES_MAX"));
我有一个 android 应用程序,它 returns 一个字符串值形成一个 table 使用游标(所以我认为只有字符串),当我尝试解析 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;
将 do 循环中的行从 getString 方法更改为 getInt 方法:
发件人:
parousies_max = cursor.getString(cursor.getColumnIndex("PAROUSIES_MAX"));
收件人:
parousies_max = cursor.getInt(cursor.getColumnIndex("PAROUSIES_MAX"));