我尝试从每个整数类型的数据库中获取数据,并将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