【发布时间】:2013-01-17 21:14:06
【问题描述】:
我做了一个简单的小部件 (AppWidgetProvider)。要加载它的内容,它需要连接到互联网(JSoup 太棒了)。显然,我有一个很棒的NetworkOnMainThreadException。我试图做一个AsyncTask,但 Eclipse 对我大喊No enclosing instance of type WidgetClass is accessible. Must qualify the allocation with an enclosing instance of type WidgetClass (e.g. x.new A() where x is an instance of WidgetClass).,所以我无法运行它。
我该如何解决?
谢谢!
【问题讨论】:
-
您收到的具体错误消息是什么?也是 Eclipse 抱怨的那一行。还要考虑使用正确的 Java 命名约定 类名以大写字母开头;变量名没有。
-
Eclipse 绝对不想要
myAsync a = new myAsync().execute()这样的东西,因为 new myAsync.execute() 可能不会返回 myAsync 的实例,除非您对其进行了编程。我相信你误会了什么。您介意提交您的代码吗? -
当我尝试
new Background().execute("");时,我得到了No enclosing instance of type Widget is accessible. Must qualify the allocation with an enclosing instance of type Widget (e.g. x.new A() where x is an instance of Widget).
标签: android multithreading exception networking widget