每当我输入一个10位数字时,我在getnum函数中从数据库中获取一个随机值,但是当我输入一个小于10位的数字时,eveything工作正常。
请告诉我们如何在getnum函数中传递一个10位数字。
public void callme(View v)
{
Intent i= new Intent();
i.setData(Uri.parse("tel:" + mydb.getnum(id_To_Update)));
i.setAction(Intent.ACTION_CALL);
startActivity(i);
}
这是我在MyDBHandler中的getnum函数
public Integer getnum(int id){
int dat =0;
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery(
"SELECT number FROM userdata1 where id="+id+"", null);
if(cursor.moveToFirst()) {
dat = cursor.getInt(0);
}
return dat;
}
这就是我创建MyDBHandler的方式
public class MyDBHandler extends SQLiteOpenHelper {
public static final int DATABASE_VERSION=1;
public static final String DATABASE_NAME = "ome1.db";
public static final String TABLE_NAME = "userdata1";
public static final String COLUMN_ID = "id";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_EMAIL = "email";
public static final String COLUMN_AMOUNT = "amount";
public static final String COLUMN_NUMBER = "number";
public MyDBHandler(Context context)
{
super(context, DATABASE_NAME , null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(
"create table userdata1 " +
"(id integer primary key, name text,email text,amount integer,number integer)"
);
}
答案 0 :(得分:0)
在上面的代码中将int更改为long,即
public Long getnum(int id){
Long dat=null;
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery(
"SELECT number FROM userdata1 where id="+id+"", null);
if(cursor.moveToFirst()) {
dat = cursor.getLong(0);
}