嘿,这是我第一次使用堆栈溢出,我试图调用另一个文件中的类(MainActivity调用FetchWeatherTask),我得到的错误不是一个封闭的类,这是抛出错误的代码
@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;
}我将尝试一些东西,但我被卡住了,完整的错误是
“com.alpha.(AppName).ForecastFragment”不是封闭类
编辑:
我正在尝试调用另一个文件中的类来获取天气数据
发布于 2014-08-13 07:14:31
ForecastFragment.FetchWeatherTask weatherTask = new ForecastFragment.FetchWeatherTask();这行代码告诉Java编译器在ForecastFragment类中查找FetchWeatherTask类。由于编译器在那里找不到FetchWeatherTask,它会报错。我怀疑您已经将FetchWeatherTask声明为顶级类,因此只需删除这两个ForecastFragment前缀(以及点)即可。
发布于 2014-08-13 06:31:40
可以使用处理程序执行在后台运行的任务。还可以尝试通过扩展AsyncTask或手动启动新线程来运行异步任务。
https://stackoverflow.com/questions/25274972
复制相似问题