任何解释为什么CursorFilter在使用这个自定义FilterQueryProvider时抛出NPE的线索?

时间:2014-12-12 15:13:42

标签: android simplecursoradapter autocompletetextview android-cursoradapter

初始化CursorAdapter后,我尝试设置以下FilterQueryProvider,以便向AutoCompleteTextView提供结果。

adapter.setFilterQueryProvider(new FilterQueryProvider() {
    @Override
    public Cursor runQuery(CharSequence constraint) {
        return databaseHelper.getReadableDatabase().rawQuery("SELECT * FROM code WHERE title MATCH ?", new String[]{constraint.toString()});
    }
});

问题在于,当我尝试在参数toString上调用constraint时,会记录NPE(可能是Log.d,因为日志是blue在logcat中。)

  

performFiltering()期间发生异常!

     

尝试调用接口方法'java.lang.String   空对象引用上的java.lang.CharSequence.toString()'

我已经检查过,约束肯定不是空的。

完整堆栈跟踪(蓝色,已捕获并已记录)

12-12 08:55:39.212   9911-10080/com.example W/Filter﹕ An exception occured during performFiltering()!
    java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
            at com.example.fragments.FooFragment$1.runQuery(FooFragment.java:102)
            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)

0 个答案:

没有答案