2016-06-29 67 views
0

調用一個方法我想打電話從的AsyncTask)稱爲getHoroscope(一個方法,從另一個類,我想這安卓:從的AsyncTask

String sentence, signo="geminis"; 
sentence = new ExtendedActivity.Parse().getHoroscope("daily",signo); 

,但我得到的錯誤「ExtendedActivity is not an enclosing class」。 你能幫我嗎?

我ExtendedActivity:

public class ExtendedActivity extends BaseActivity { 
(...) 
public class Parse extends AsyncTask<String, Void, String> { 

     private final ProgressDialog dialog = new ProgressDialog(ExtendedActivity.this); 


     @Override 
     public String doInBackground(String... params) { 

      String option, type, dat, site="", description="", s="";; 

      //get the user option 
      Bundle extras = getIntent().getExtras(); 
      option = extras.getString("OPTION"); 
      type = extras.getString("TYPE"); 

      description = getHoroscope(type, option); 

      return description; 
     } 


     public String getHoroscope(String type, String option){ 
      String description="", site; 
      (...) 
     } 
    } 
+0

您正在創建ExtendedActivity的對象並嘗試從Parse()類靜態訪問一個方法。要麼聲明Parse和getHoroscope是靜態的,要麼創建一個Parse對象 –

+0

可能重複[不是封閉類Java](http://stackoverflow.com/questions/20252727/is-not-an-enclosing-class-java) –

+0

你在哪裏調用'AsyncTask.execute'? –

回答

0

你CAND·其:

new ExtendedActivity().new Parse().getHoroscope();

或:

public class ExtendedActivity { 
    public static class Parse extends AsyncTask<String, Void, String> { 

     @Override 
     public String doInBackground(String... params) { 

      String description = ""; 

      description = getHoroscope(); 

      return description; 
     } 


     public static String getHoroscope() { 
      return null; 
     } 
    } 
} 

,並調用它像:new ExtendedActivity.Parse().getHoroscope();