单击搜索时,我的应用程序已停止

时间:2013-07-15 12:32:10

标签: java android

我正在使用搜索来显示列表视图内容。在单击搜索功能或键入任何数据时,它会显示我的应用程序已停止。

Mainactivity.java

@SuppressLint("NewApi")
     @SuppressWarnings("deprecation")
       private void fillData(Cursor projectsCursor) {
           //mDbHelper.open();   

           if(projectsCursor!=null)
           {
           String[] from = new String[]{GinfyDbAdapter.CATEGORY_COLUMN_TITLE, GinfyDbAdapter.CATEGORY_COLUMN_CONTENT, GinfyDbAdapter.CATEGORY_COLUMN_COUNT};
           int[] to = new int[]{R.id.text2, R.id.text1, R.id.count};
            dataAdapter  = new SimpleCursorAdapter(
             this, R.layout.activity_row, 
             projectsCursor, 
             from, 
             to,
             0);
            setListAdapter(dataAdapter);

            EditText myFilter = (EditText) findViewById(R.id.myFilter);
              myFilter.addTextChangedListener(new TextWatcher() {

               public void afterTextChanged(Editable s) {
               }

               public void beforeTextChanged(CharSequence s, int start, 
                 int count, int after) {
               }

               public void onTextChanged(CharSequence s, int start, 
                 int before, int count) {
                   dataAdapter.getFilter().filter(s.toString());
               }
              });

              dataAdapter.setFilterQueryProvider(new FilterQueryProvider() {
                     public Cursor runQuery(CharSequence constraint) {
                         return mDbHelper.fetchProjectByName(constraint.toString());
                     }
                 });

这是我的db.java

 public Cursor fetchProjectByName(String inputText) throws SQLException {
          Log.w(TAG, inputText);
          Cursor mCursor = null;
          if (inputText == null  ||  inputText.length () == 0)  {
           mCursor = mDb.query(DATABASE_TABLE_PROJ, new String[] {CATEGORY_COLUMN_ID,
                 CATEGORY_COLUMN_CONTENT}, 
             null, null, null, null, null);

          }
          else {
           mCursor = mDb.query(true, DATABASE_TABLE_PROJ, new String[] {CATEGORY_COLUMN_ID,
                 CATEGORY_COLUMN_CONTENT}, 
                CATEGORY_COLUMN_CONTENT + " like '%" + inputText + "%'", null,
             null, null, null, null);
          }
          if (mCursor != null) {
           mCursor.moveToFirst();
          }
          return mCursor;

         }

按名称在fetchproject中使用db我想根据我的搜索选项搜索listview的内容。它显示了一些logcaterror。 在键入或单击搜索区域时,它显示我的应用程序已停止。

这是我的logcat错误。

07-15 12:23:08.688: E/AndroidRuntime(25812): FATAL EXCEPTION: main
07-15 12:23:08.688: E/AndroidRuntime(25812): java.lang.IllegalArgumentException: column 'title' does not exist
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:333)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.widget.SimpleCursorAdapter.swapCursor(SimpleCursorAdapter.java:345)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.widget.CursorAdapter.changeCursor(CursorAdapter.java:309)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.widget.CursorFilter.publishResults(CursorFilter.java:67)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.os.Looper.loop(Looper.java:137)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at android.app.ActivityThread.main(ActivityThread.java:5039)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at java.lang.reflect.Method.invokeNative(Native Method)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at java.lang.reflect.Method.invoke(Method.java:511)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-15 12:23:08.688: E/AndroidRuntime(25812):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

在查询中添加标题列。

mCursor = mDb.query(DATABASE_TABLE_PROJ, 
new String[]{CATEGORY_COLUMN_ID,CATEGORY_COLUMN_TITLE,
CATEGORY_COLUMN_CONTENT}, 
null, null, null, null, null);