gpt4 book ai didi

java - 一个android数据库问题

转载 作者:行者123 更新时间:2023-11-30 09:49:47 25 4
gpt4 key购买 nike

当我在 SQ lite 中调用我已经创建的数据库时。它给出了数据库正在递归调用的运行时异常。但是每次数据库使用结束时我都会关闭它。它出了什么问题?我正在使用 eclipse 并在 android 中开发程序。

我创建了助手类的对象(我在其中创建了数据库)。然后使用 SQliteDatabase db=hc.getWritebleDatabase();异常在上面一行

hc=helperclass object

回答我..因为在谷歌上我没有得到任何相关的答案。

代码获取异常:::我已经有一个名为 HelperClass 的数据库类。它有一个名为 New_User 的表

public void check_pass()
{
boolean flag=true;
private HelperClass hc = new HelperClass(this);
SQLiteDatabase db;
try{ db=hc.getWritableDatabase();}

catch(Exception ex)
{
Toast.makeText(this,""+ex.getMessage(),Toast.LENGTH_SHORT).show();
}
cur=db.query("New_User",null,null,null,null,null,null);
cur.moveToFirst();
do{
if(cur.getString(0).equalsIgnoreCase(edittext_name.getText().toString())&&cur.getString(3).equals(edittext_pass.getText().toString())){
flag=false;

//dialog = ProgressDialog.show(MainActivity.this,"","Please wait for few seconds...", true);
//dialog.setCancelable(true);
//dialog.show();
Intent intent1=new Intent(this,Friends.class);
startActivity(intent1);
}
cur.moveToNext();
} while(cur.moveToNext());
if(flag==true){
Toast.makeText(this,"Incorecct user name or password",Toast.LENGTH_SHORT).show();
}

数据库创建:

public class HelperClass extends SQLiteOpenHelper {
public final static String Db_name="employee.db";
protected final static int Db_version=1;
protected final static String Ename="Ename";
protected final static String Email="Email";
protected final static String Epass="Epass";
protected final static String Eabout="Eabout";
protected final static String Egender="Egender";
protected final static String Ehob1="Ehob1";
protected final static String Ehob2="Ehob2";
protected final static String Ehob3="Ehob3";
protected final static String Ehob4="Ehob4";


public HelperClass(Context context){
super(context,Db_name,null,Db_version);
}

public void onCreate(SQLiteDatabase db1){
db1=this.getWritableDatabase();
String sql= "CREATE TABLE New_User("+Ename +" text not null," +
""+ Egender +" text not null," +
""+ Email +" text not null primary key," +
"" +Epass+" text not null,"+
""+ Eabout +" text not null,"+
""+ Ehob1 +" text,"+ Ehob2 +" text,"+ Ehob3 +" text,"+ Ehob4 +" text);";
db1.execSQL(sql);

}

最佳答案

删除这一行:

db1=this.getWritableDatabase();

所以你的数据库 onCreate 方法应该是:

public void onCreate(SQLiteDatabase db1){
String sql= "CREATE TABLE New_User("+Ename +" text not null," +
""+ Egender +" text not null," +
""+ Email +" text not null primary key," +
"" +Epass+" text not null,"+
""+ Eabout +" text not null,"+
""+ Ehob1 +" text,"+ Ehob2 +" text,"+ Ehob3 +" text,"+ Ehob4 +" text);";
db1.execSQL(sql);
}

关于java - 一个android数据库问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5590614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com