当我在SQ lite中调用我已创建的数据库时。它给出了数据库递归调用的运行时异常。但每次数据库使用结束时我都关闭它。 它出了什么问题?我正在使用eclipse并在android中开发程序。
我创建了辅助类的对象(我在其中创建了数据库)。然后
使用SQliteDatabase db=hc.getWritebleDatabase();
例外情况在上面一行
hc=helperclass object
回答我。因为在Google上我没有得到任何相关的答案。
代码获取异常::: 我已经有一个名为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);
}
答案 0 :(得分:2)
删除此行:
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);
}
答案 1 :(得分:0)
使用数据库对象后关闭 * 强文 * SQLiteDataBase.close();