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

2
  • you only included part of your class, so it's hard to be sure, but in the code you posted, you are missing a closing }. Commented Aug 12, 2014 at 22:16
  • Which line gives the error? Commented Aug 12, 2014 at 23:12

2 Answers 2

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).

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

1 Comment

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
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.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.