2016-07-27 32 views
-1

我有一個class B和有我想調用一個方法getSomething(type, option),屬於class的方法的延伸AsyncTask和裏面class C.機器人:調用屬於的AsyncTask類

class我C是:

public class C extends BaseActivity{ 
(...) 
public class A extends AsyncTask<String, Void, String> { 
(...) 
    public String doInBackground(String... params) { 
    (...) 
    } 
    public String getSomething(String type, String option){ 
    (...) 
    } 
    protected void onPreExecute() { 
    (...) 
    } 
    protected void onPostExecute(String result){ 
    (...) 
    } 
(...) 
} 

我想在B類調用的方法getSomething(...)

public class B{ 
(...) 
public void methodInClassB(String type, String option){ 

    String sentence = new C().new A().getSomething(type,option); 
} 

我也沒能成功的:

new C().new A().execute(type,option); 

我不能叫getSomething()方法,因爲我得到以下異常:

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference 
每次被B.

稱爲 class時間

有人可以幫助我嗎?我如何從B類調用方法getSomething(...)?

回答

0

問題似乎不清楚 試試這個

  • B類內保持調用異步任務的方法 - methodInClassB
  • 使用您的葡萄乾類
  • 調用B類創建類B的對象你對象和調用方法InClassB
+0

我已經爲你編輯了這篇文章,瞭解我是如何獲得B類的。在類B中,我有一個方法,並且在該方法中,我想從AsyncTask()調用getSomething()。 – porthfind