I am trying to work with AutoCompleteText and SimpleCusorAdapte to retrieve data from sqlite database. when I input first letter to AutoCompleteText it's show "Println Needs a Message" Error and doesn't show result. but at meantime I enter the second letter and it's show result. why that it happen and how can i solve this?
this is logcat
W/Filter: An exception occured during performFiltering()!
java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.v(Log.java:121)
at com.example.dilanka.ypbrothers.DbAdapter.fetchCustomersByName(DbAdapter.java:178)
at com.example.dilanka.ypbrothers.CreateInvoice$3.runQuery(CreateInvoice.java:80)
at android.widget.CursorAdapter.runQueryOnBackgroundThread(CursorAdapter.java:395)
at android.widget.CursorFilter.performFiltering(CursorFilter.java:49)
at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
P.S:DbAdapter.java:178 - Log.v(TAG, inputText);
CreateInvoice.java:80 - return dbHelper.fetchCustomersByName((constraint != null ? constraint.toString() : null));
This is some of code of DbAdapter.java
public Cursor fetchCustomersByName(String inputText) throws SQLException {
Log.v(TAG, inputText); //This is DbAdapter.java:178 line
Cursor mCursor = null;
if (inputText == null || inputText.length () == 0) {
mCursor = mDb.query(CusDet_TABLE, new String[] {CusDet_COL_1,CusDet_COL_2, CusDet_COL_3,
CusDet_COL_4, CusDet_COL_5, CusDet_COL_6, CusDet_COL_7, CusDet_COL_8},
null, null, null, null, " _name COLLATE NOCASE");
}
else {
mCursor = mDb.query(true, CusDet_TABLE, new String[] {CusDet_COL_1,CusDet_COL_2, CusDet_COL_3,
CusDet_COL_4, CusDet_COL_5, CusDet_COL_6, CusDet_COL_7, CusDet_COL_8},
CusDet_COL_3 + " like '%" + inputText + "%'", null,
null, null, " _name COLLATE NOCASE",null);
}
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
This is code of Activity:
final int[] to = new int[] { android.R.id.text1 };
final String[] from = new String[] { "_name" };
dbHelper = new DbAdapter(this);
dbHelper.open();
acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this,
android.R.layout.simple_dropdown_item_1line,
null,
from,
to);
acTextView.setAdapter(adapter);
acTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor = (Cursor) parent.getItemAtPosition(position);
String capital = cursor.getString(cursor.getColumnIndexOrThrow("_name"));
}
});
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
@Override
public CharSequence convertToString(Cursor cursor) {
final int columnIndex = cursor.getColumnIndexOrThrow("_name");
final String str = cursor.getString(columnIndex);
return str;
}
});
adapter.setFilterQueryProvider(new FilterQueryProvider() {
@Override
public Cursor runQuery(CharSequence constraint) {
return dbHelper.fetchCustomersByName((constraint != null ? constraint.toString() : null));//This is CreateInvoice.java:80 line
}
});
Aucun commentaire:
Enregistrer un commentaire