从数据库填充TextWatcher(sqlite)

时间:2015-08-21 13:55:02

标签: android sqlite

我尝试从每个整数类型的数据库中获取数据,并将Text设置为另外两个EditText但是当我按任意键App崩溃时

这是我的尝试:

    protected final TextWatcher BarCodeWatcher = new TextWatcher() {
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        Cursor cursor = mDbHelper.getTestData(s.toString());

        Log.e("Hello :",cursor.getString(cursor.getColumnIndex("Item_Name")));
        if (cursor.getCount() != 0) {

            String itemName = cursor.getString(cursor.getColumnIndex("Item_Name"));
            itemNameEdit.setText(itemName);
            String unitPrice = cursor.getString(cursor.getColumnIndex("Sale_Price"));
            unitPriceEdit.setText(unitPrice);
            cursor.close();
        }
    }

    public void afterTextChanged(Editable s) {
    }
};

** Logcat:**

Process: com.example.fani.project, PID: 29441
java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.rawQuery(java.lang.String, java.lang.String[])' on a null object reference

0 个答案:

没有答案