Android 列';名称';不存在
我正在开发一个应用程序,我遇到了这个问题,我做了一切,但仍然没有解决,它包含一个Android 列';名称';不存在,android,database,eclipse,sqlite,Android,Database,Eclipse,Sqlite,我正在开发一个应用程序,我遇到了这个问题,我做了一切,但仍然没有解决,它包含一个错误=“column'name'不存在” 如果可能的话,给我一些解决这个问题的建议 我还删除了电话里的数据库, 请帮帮我 提前谢谢 public class DataBaseBON { String TAG; private Context ourContext; private dbhelper ourhelper; private SQLiteDatabase
错误=“column'name'不存在”
如果可能的话,给我一些解决这个问题的建议
我还删除了电话里的数据库,
请帮帮我
提前谢谢
public class DataBaseBON {
String TAG;
private Context ourContext;
private dbhelper ourhelper;
private SQLiteDatabase ourdatabase;
public final static String KEY_ID= "_id";
public final static String KEY_NUMBER="blockednumbers";
public final static String N_NAME="name";
public final static String DATABASE_NAME="databasebon.db";
public final static String DATABASE_TABLE="tabledb";
public final static int DATABASE_VERSION=2;
private static final String DATABASE_CREATE = "create table "
+ DATABASE_TABLE + "(" + KEY_ID
+ " integer primary key autoincrement, "
+ N_NAME + " text not null,"
+ KEY_NUMBER
+ " text not null);";
public class dbhelper extends SQLiteOpenHelper{
public dbhelper(Context context) { //?
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(dbhelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
}
public DataBaseBON(Context c){
ourContext =c ;
}
public DataBaseBON open() throws SQLException{
ourhelper = new dbhelper(ourContext);
ourdatabase = ourhelper.getWritableDatabase();
ourdatabase=ourhelper.getReadableDatabase();
return this;
}
public void close(){
ourhelper.close();
}
public long creatEntry(String inputnumber , String name) {
// TODO Auto-generated method stub
ContentValues cv= new ContentValues();
cv.put(KEY_NUMBER, inputnumber);
cv.put(N_NAME, name);
Log.v(inputnumber, "adding to Database");
return ourdatabase.insert(DATABASE_TABLE, null, cv);
}
public Cursor getcursor() {
String[] columns = new String[]{ N_NAME, KEY_NUMBER };
Cursor c=ourdatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
return c;}
public String[] getcloumns() {
String[] columns = new String[]{ N_NAME, KEY_NUMBER };
return columns ;
}
public int[] getto() {
String TAG = null;
int[] to = new int[] { android.R.id.text1, android.R.id.text2 };
Log.v(TAG, "get to is ok");
return to ;
}
public String[] getdata3(String[] result) {
String TAG = null;
String[] columns = new String[]{ N_NAME, KEY_NUMBER };
Cursor c=ourdatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
int iRow = c.getColumnIndex(N_NAME);
int iName = c.getColumnIndex(KEY_NUMBER);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
@SuppressWarnings("unused")
String[] result1= new String[] {c.getString(iName),c.getString(iRow)};
Log.v(TAG, "is ok");
}
return result;
}
错误:
11-25 23:49:33.633: E/AndroidRuntime(4072): java.lang.RuntimeException: Unable to startactivity
ComponentInfo{vahid.engineer.com/vahid.engineer.com.BlackNumbersBlockDb}:
java.lang.IllegalArgumentException: column 'name' does not exist
您需要在dbhelper上使用此行
this.db = this.getWritableDatabase();
否则,不会调用onCreate。请注意,您还需要一个“Database db”变量
有点晚,但总比没有晚好我遇到了这样的问题,我正在使用content provider,因此当您投影表的属性时,任何未投影的属性对于基本uri都将不可见,因此要更正此问题,请投影表的所有属性
projectionMap.put(Tablename.Attribute1,Tablename.Attribute1) ;代码>正在创建您的表吗?您检查过了吗?请尝试sqlite浏览器,并在我运行它时验证是否正在创建您的表,而我的手机中没有“name”列,我可以看到数据库,但当我尝试添加名称时,我遇到了这个问题,我将数据库版本更改为3,现在我有了新的错误,即AndroidRuntime(5003):原因:java.lang.IllegalArgumentException:列“\u id”不存在您是否尝试更改列名称?在执行onCreate方法时,日志是否有任何错误?(也许try/catch语句会有帮助)谢谢你的回答,但我在这部分之前做过:public DataBaseBON open()抛出SQLException{ourhelper=new dbhelper(ourContext);ourdatabase=ourhelper.getwriteabledatabase();ourdatabase=ourhelper.getReadableDatabase();返回此;}