我试图用AutoCompleteText和SimpleCusorAdapte工作检索SQLite数据库的数据。当我输入第一个字母AutoCompleteText它的秀的println需要消息的错误和不显示结果。但与此同时,我进入第二个字母,它的显示效果。为什么它发生,我怎么能解决这个问题?
这是logcat的
W /过滤器:performFiltering过程中发生异常()!显示java.lang.NullPointerException:需要的println消息在android.util.Log.println_native(本机方法)在android.util.Log.v(Log.java:121)在com.example.dilanka.ypbrothers.DbAdapter.fetchCustomersByName(DbAdapter.java:178)在com.example.dilanka.ypbrothers.CreateInvoice $ 3.runQuery(CreateInvoice.java:80)在android.widget.CursorAdapter.runQueryOnBackgroundThread(CursorAdapter.java:395)在android.widget.CursorFilter.performFiltering(CursorFilter.java:49)在android.widget.Filter $ RequestHandler.handleMessage(Filter.java:234)在android.os.Handler.dispatchMessage(Handler.java:102)在android.os.Looper.loop(Looper.java:135)在android.os.HandlerThread.run(HandlerThread.java:61)P.S:DbAdapter.java:178 - Log.v(TAG,inputText的); CreateInvoice.java:80 - 返回dbHelper.fetchCustomersByName((约束= NULL constraint.toString():空)!?);
这是一些DbAdapter.java的code
的 公共光标fetchCustomersByName(字符串inputText的)抛出的SQLException { Log.v(TAG,inputText的); //这是DbAdapter.java:178线 光标mCursor = NULL; 如果(inputText的== NULL || inputText.length()== 0){ mCursor = mDb.query(CusDet_TABLE,新的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); } 其他{ mCursor = mDb.query(真,CusDet_TABLE,新的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,_name COLLATE NOCASE,NULL); } 如果(mCursor!= NULL){ mCursor.moveToFirst(); } 返回mCursor;}
这是活动的code:
最终诠释[]为= INT新[] {} android.R.id.text1;最终的String [] =由新的String [] {_name};dbHelper =新DbAdapter(本);dbHelper.open();acTextView =(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);SimpleCursorAdapter适配器=新SimpleCursorAdapter( 本, android.R.layout.simple_dropdown_item_1line, 空值, 从, 至);acTextView.setAdapter(适配器);acTextView.setOnItemClickListener(新AdapterView.OnItemClickListener(){ @覆盖 公共无效onItemClick(适配器视图<>母公司,观景,INT位置,长的id){ 光标光标=(光标)parent.getItemAtPosition(位置); 字符串资本= cursor.getString(cursor.getColumnIndexOrThrow(_名)); }});adapter.setCursorToStringConverter(新SimpleCursorAdapter.CursorToStringConverter(){ @覆盖 公共CharSequence的convertToString(光标光标){ 最终诠释参数:columnIndex = cursor.getColumnIndexOrThrow(_名); 最终字符串str = cursor.getString(参数:columnIndex); 返回海峡; }});adapter.setFilterQueryProvider(新FilterQueryProvider(){ @覆盖 公共光标runQuery(CharSequence的约束){ 返回dbHelper.fetchCustomersByName((约束= NULL constraint.toString():!NULL)); //这是CreateInvoice.java:80线 }});
更新:我的问题还没解决。之后,我改变Log.v(TAG,inputText的);到Log.v(TAG的inputText:+ inputText的);在需要的println消息错误没有显示。但是当我输入一个字母的logcast秀的inputText:空,不显示一个字母的结果。根据现在的情况,我必须输入两个或多个字符得到的结果。如何解决呢?
解决方案 Log.v(TAG,inputText的); //这是DbAdapter.java:178线
您正在试图登录导致此异常的空
消息。
将其更改为例如。
Log.v(TAG的inputText:+ inputText的);
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
}
});
Update: My problem hasn't solved yet. After i change Log.v(TAG, inputText); to Log.v(TAG, "inputText:" + inputText); the "Println Needs a Message" error isn't show. but when I input one letter the logcast show "inputText: null" and doesn't show result for one letter. according to now situation i have to enter two or more than character to get result. how can i solve that?
解决方案Log.v(TAG, inputText); //This is DbAdapter.java:178 line
You're attempting to log a null
message that causes this exception.
Change it to e.g.
Log.v(TAG, "inputText:" + inputText);
上一篇:如何从一个Windows服务使用C#访问Linux的目录/文件文件、目录、Windows、Linux
下一篇:在 Metro Style 应用程序上计算 ViewBox ScaleFactor应用程序、Style、Metro、ViewBox