一夜的错误 : simpleCursorAdapter column '_id' does not exist

在做一个关于simpleCursorAdapter   和 ListView 绑定的时候,建立数据表的时候 数据库主键没有用 “_id” 而是自己定义的一个 ,

 

谁知老出现 column '_id' does not exist 的异常,弄的程序崩溃,也把我搞崩溃了,google 了 好久,到几个国外的网站上也查了,

 

也有遇到类似问题的,性感欣慰啊!

 

不过 他们没有解决的方法,哎, 这可把哥郁闷死了,该死的google  ,那么龌龊。

 

后来在新浪的博客 :http://blog.sina.com.cn/s/blog_507e84890100gea2.html

 

看见了这个大哥的总结,呵呵 很高兴,希望大家 遇到这个样的错误可以看见这篇文章,少走弯路!

 

我感觉 ,遇到问题 ,学会 收索的技巧 和 分析问题的方法 是很重要的,要不然我是解决不了这个问题的 。呵呵

 

 

public class MerchantActivity extends AppCompatActivity { private EditText mNameEditText; private EditText mPriceEditText; private Button mAddButton; private ListView mListView; private DBHelper mDBHelper; private SQLiteDatabase mDatabase; private Cursor mCursor; private SimpleCursorAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_merchant); mNameEditText = findViewById(R.id.edit_text_name); mPriceEditText = findViewById(R.id.edit_text_price); mAddButton = findViewById(R.id.button_add); mListView = findViewById(R.id.list_view); mDBHelper = new DBHelper(this); mDatabase = mDBHelper.getWritableDatabase(); updateUI(); mAddButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name = mNameEditText.getText().toString(); String price = mPriceEditText.getText().toString(); ContentValues values = new ContentValues(); values.put(DBHelper.COLUMN_NAME, name); values.put(DBHelper.COLUMN_PRICE, price); mDatabase.insert(DBHelper.TABLE_NAME, null, values); updateUI(); } }); } private void updateUI() { mCursor = mDatabase.query(DBHelper.TABLE_NAME, null, null, null, null, null, null); mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, mCursor, new String[]{DBHelper.COLUMN_NAME, DBHelper.COLUMN_PRICE}, new int[]{android.R.id.text1, android.R.id.text2}, 0); mListView.setAdapter(mAdapter); } @Override protected void onDestroy() { super.onDestroy(); mDatabase.close(); mCursor.close(); } }什么意思
最新发布
06-03
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值