java java应用程序开发错误未包含类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25274972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java app developement error is not enclosing class
提问by Ryan Doherty
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
嘿,这是我第一次使用堆栈溢出,我正在尝试调用不同文件中的类(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;
}
im going to try a few things but I am stuck the full error is
我要尝试一些事情,但我被卡住了完整的错误是
'com.alpha.(appName).ForecastFragment' is not an enclosing class
'com.alpha.(appName).ForecastFragment' 不是封闭类
EDIT:
编辑:
im trying to call a class in a different file to get the weather data
我试图在不同的文件中调用一个类来获取天气数据
采纳答案by Code-Apprentice
ForecastFragment.FetchWeatherTask weatherTask = new ForecastFragment.FetchWeatherTask();
This line of code tells the Java compiler to look for the FetchWeatherTaskclass inside the ForecastFragmentclass. Since the compiler cannot find FetchWeatherTaskthere, it complains. I suspect that you have declared FetchWeatherTaskas a top-level class, so you can simply remove both ForecastFragmentprefixes (and the dot as well).
这行代码告诉 Java 编译器在FetchWeatherTask类中查找ForecastFragment类。由于编译器找不到FetchWeatherTask那里,它抱怨。我怀疑您已声明FetchWeatherTask为顶级类,因此您可以简单地删除两个ForecastFragment前缀(以及点)。
回答by Ali
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.
您可以使用处理程序来执行在后台运行的任务。还可以尝试通过扩展 AsyncTask 或手动启动新线程来运行 Async 任务。

