1

我有一个需要调用另一个的静态类,第一个是静态的,并阻止我调用第二个并出现以下错误:

No enclosing instance of type Studies is accessible. Must qualify the allocation with an enclosing instance of type Studies (e.g. x.new A() where x is 
 an instance of Studies).

异步任务类

    class DownloadFileAsync extends AsyncTask<String, String, String> {

        @Override
        protected void onPreExecute() {}

        @Override
        protected String doInBackground(String... aurl) {}
    }

静态类

     public static void startDownload(int id) {
         ERROR LINE--> new DownloadFileAsync().execute("SOME URL");
   }

谢谢!

4

3 回答 3

1

你可以试试new Studies().new DownloadFileAsync().execute("SOME URL");

但这不完全是 OOP 风格

于 2012-07-12T12:49:27.297 回答
0

你有没有看到这个答案。回答链接

于 2012-07-12T12:35:39.957 回答
0

这是一个老问题,但如果有人仍然感兴趣,而不是在你的静态类中定义你的 AsyncTask,你可以在它自己的文件中定义它,这样就可以了。

于 2013-08-17T20:42:04.133 回答