如何在mainactivity中定义dbhandler构造函数变量?

时间:2013-09-17 17:41:53

标签: android sqlite

dbhandler类

public class DBHandler extends SQLiteOpenHelper{

private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "feedbackDB.db";
private static final String TABLE_FEEDBACK = "feedback";
private static final String DB_PATH = "/data/data/com.example.vbfeed/databases/";

public DBHandler(Context context, String name,CursorFactory factory, int version) {
        super(context,context.getExternalFilesDir(null).getAbsolutePath() + DB_PATH + DATABASE_NAME, factory, DATABASE_VERSION);

    }

onCreate下的主要活动代码和点击

上的按钮
DBHandler dbHandler = new DBHandler(getBaseContext(),name,null, 1);
//having error in this line--just constructor defining error,
//i dono the variables to declare

1 个答案:

答案 0 :(得分:0)

将构造函数更改为

  public DBHandler(Context context) { 
  super(context, DATABASE_NAME, null, DATABASE_VERSION);
  } 

并使用

  DBHandler db = new DBHnadler(this);

http://www.vogella.com/articles/AndroidSQLite/article.html

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

请查看以上链接以供参考。