1

Hey this is my first time using stack overflow and I am trying to call a class in a different file (MainActivity calling FetchWeatherTask) I am getting the error is not an enclosing class this is code is throwing the error

 @Override
    public boolean onOptionsItemSelected (MenuItem item){
        int id = item.getItemId();
        if (id == R.id.action_refresh) {
            ForecastFragment.FetchWeatherTask weatherTask = new ForecastFragment.FetchWeatherTask();
            weatherTask.execute();
            return true;
        }

im going to try a few things but I am stuck the full error is

'com.alpha.(appName).ForecastFragment' is not an enclosing class

EDIT:

im trying to call a class in a different file to get the weather data

Ryan Doherty
  • 140
  • 1
  • 1
  • 9

2 Answers2

1
ForecastFragment.FetchWeatherTask weatherTask = new ForecastFragment.FetchWeatherTask();

This line of code tells the Java compiler to look for the FetchWeatherTask class inside the ForecastFragment class. Since the compiler cannot find FetchWeatherTask there, it complains. I suspect that you have declared FetchWeatherTask as a top-level class, so you can simply remove both ForecastFragment prefixes (and the dot as well).

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Thanks I realized after reading this that I had FetchWeatherTask inside the other class and I moved it to its own file and everything see,s alright – Ryan Doherty Aug 12 '14 at 23:36
0

You can use Handlers to perform tasks that run in background. Also try to run an Async task by either extending the AsyncTask or starting a new thread manually.

Ali
  • 1
  • in this im trying to run a class that gets weather data from open weather map which extends asynctask im still fairly new to this – Ryan Doherty Aug 12 '14 at 23:01