2011-11-09 79 views
0

基本問題 - 我仍在學習Android - 嘗試創建一個單獨的線程來執行數據庫查詢並遇到問題。我已經把我的數據庫程序在自己的類,但似乎無法從線程訪問:Android線程訪問數據庫類

public class TripsScreenActivity extends Activity implements OnClickListener { 

public class dbThread extends AsyncTask<Cursor, Integer, Cursor> { 

    @Override 
    protected Cursor doInBackground(Cursor... arg0) { 
     // TODO Auto-generated method stub 

     // Link to WYWHApplication module 
     WYWHApplication wywh = (WYWHApplication) this.getApplication(); 

     try { 
      Cursor tripList = wywh.getBasicList(); 

...但是Eclipse是給我以下錯誤:

The method getApplication() is undefined for the type TripsScreenActivity.dbThread 

對不起,可能是一個明顯的答案...任何幫助感激地接受。

回答

2

thisdoInBackground()。您使用時要引用您的活動,所以使用TripsScreenActivity.this.getApplication()¹,而不是this.getApplication()AsyncTask

¹這就是所謂的「合格這個」

+0

優秀的 - 非常感謝......,工程;-) – Nelmo

+1

啊,對不起,不知道 - 現在做... – Nelmo