android 提示这个错误 Caused by: android.database.sqlite.SQLiteException: no such column: xuehao:
这句话产生的 Cursor cur=database.query(tablename, new String[]{XUEHAO,xingming}, null, null, null, null, null);
这个所有代码 public class Shu extends Activity {
private static int miCount = 0;
private ListView list;
private SQLiteDatabase database;
private static String databasename="xuesheng.db";
private static String tablename="table1";
private static String XUEHAO="xuehao";
private static String xingming="xingming";
private static String createtable="CREATE TABLE "+tablename+"("+XUEHAO+" INTEGER PRIMARY KEY,"+xingming+"TEXT)";
private Button add;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list=(ListView)findViewById(R.id.listView1);
add=(Button)findViewById(R.id.button1);
database=this.openOrCreateDatabase(databasename, MODE_PRIVATE, null);
try
{
/* 在数据库mSQLiteDatabase中创建一个表 */
database.execSQL(createtable);
}
catch (Exception e)
{
audata();
}
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AddData();
}
}) ;
}
public void AddData()
{
ContentValues cv = new ContentValues();
cv.put(XUEHAO, "111");
cv.put(xingming, "sdaf");
/* 插入数据 */
database.insert(tablename, null, cv);
miCount++;
audata();
}
private void audata(){
Cursor cur=database.query(tablename, new String[]{XUEHAO,xingming}, null, null, null, null, null);
miCount = cur.getCount();
if (cur != null && cur.getCount() >= 0)
{
ListAdapter adapter=new SimpleCursorAdapter(this,
android.R.layout.易做图_list_item_2,
cur,
new String[]{XUEHAO,xingming},
new int[]{android.R.id.text1,android.R.id.text2});
list.setAdapter(adapter);
}
}}
追问:我的意思是 这个错误是什么造成的 , 提示是没有xuehao 课一我已经定义了啊我的意思是 这个错误是什么造成的 , 提示是没有xuehao 课一我已经定义了啊
答案:Caused by: android.database.sqlite.SQLiteException: no such column: Li:SQL代码没写对,用字符串查询的时候要加单引号如 name=’Li‘,注意单引号
其他:没太听明白~ 不大懂你的意思~
上一个:我想把从sqlite数据库里读出来的数据在asp.net里转换成utf-8的,该怎么做?
下一个:sqlite 默认编码是什么