0

I want to call a method called getHoroscope() from an AsyncTask, from another class, I'm trying this

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

But I get error "ExtendedActivity is not an enclosing class". Can you help me?

My 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; (...) } } 
3
  • You are creating an object of ExtendedActivity and trying to access statically a method from Parse () class. Either, declare Parse and getHoroscope static or create an object of Parse Commented Jun 29, 2016 at 15:18
  • Possible duplicate of Is not an enclosing class Java Commented Jun 29, 2016 at 15:21
  • Where u are calling AsyncTask.execute ?: Commented Jun 29, 2016 at 15:32

1 Answer 1

0

You cand o it:

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

or:

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; } } } 

and call it like that: new ExtendedActivity.Parse().getHoroscope();

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.