2013-06-07 2 views
0

AsyncTask에 SimpleCursorAdapter를 추가하려고 할 때 왜 오류가 발생하는지 알 수 없습니다.AsyncTask의 android SimpleCursorAdapter에서 오류가 발생했습니다.

private class LoadNewsLists extends AsyncTask<String, Void, Cursor> { 
    @Override 
    protected void onPreExecute() {   
    } 


    @Override 
    protected Cursor doInBackground(final String... args) { 
     Cursor cursor = dbHelper.fetchMainActivity(); 
     return cursor; 
    } 


    protected void onPostExecute(final Cursor cursor) { 
     String[] columns = new String[] { 
        DatabaseUtil.rtitle, 
        DatabaseUtil.rtypeof 
      }; 

      // the XML defined views which the data will be bound to 
      int[] to = new int[] { 
      R.id.idTitle, 
      R.id.idType 
      }; 

      // create the adapter using the cursor pointing to the desired data 
      //as well as the layout information 
      dataAdapter = new SimpleCursorAdapter(
      MainActivity.this, R.layout.listhome, 
      cursor, 
      columns, 
      to, 
      0); 

      listView = (ListView) findViewById(R.id.list); 
      listView.setAdapter(dataAdapter);   
    } 

위의 코드를 렌더링 할 때 오류가 발생했습니다.

06-07 09:14:33.496: E/AndroidRuntime(21735): Caused by: java.lang.NullPointerException 
06-07 09:14:33.496: E/AndroidRuntime(21735):  
at com.ppshein.test.MainActivity$LoadNewsLists.doInBackground(MainActivity.java:38) 

답변

0

dbHelper 인스턴스에서 확인하십시오. 이 줄은 NPE를 통해 전달됩니다. 즉,이 줄은 NPE를 통해 전달됩니다.

+0

어떤 쓰레기 ...! 감사. 나는 dbHelper를 초기화하는 것을 잊었다. – ppshein

+0

일반적으로 발생합니다 ... – Daniel

관련 문제