RSS阅读器,,,作用域内没有类型为Main2的封闭实例

阿拉莫

我想制作RSS阅读器,但是我在onpostexecute上为arrayadapter定义了一个问题“无法在范围内访问Main2类型的封闭实例”,无法为“这个”类定义我搜索该问题,但是找不到解决方案>>>请任何人都可以帮助:(

public class Main2 extends ListActivity {
Button grow, price, disease;
Intent go, pr, dis;
List headlines;
List links;

public Main2() {
    // TODO Auto-generated constructor stub
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    // Binding data
    // ArrayAdapter adapter = new ArrayAdapter(this,
    // android.R.layout.simple_list_item_1, headlines);
    //
    // setListAdapter(adapter);
    new GetRSS().execute();

    grow = (Button) findViewById(R.id.bt_plants);
    price = (Button) findViewById(R.id.bt_prices);
    disease = (Button) findViewById(R.id.bt_diseases);
    grow.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            go = new Intent(getApplicationContext(), Plantgrow.class);
            startActivity(go);
        }
    });
    price.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            pr = new Intent(getApplicationContext(), Price.class);
            startActivity(pr);

        }
    });
    disease.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            dis = new Intent(getApplicationContext(), Diseases.class);
            startActivity(dis);
        }
    });

}

protected void onListItemClick(ListView l, View v, int position, long id) {
    Uri uri = Uri.parse((String) links.get(position));
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main2, menu);
    return true;
}

}

class GetRSS extends AsyncTask<String, String, List> {
List Aheadlines, Alinks;

protected List doInBackground(String... args) {
    // List headlines, links;
    Aheadlines = new ArrayList();
    Alinks = new ArrayList();

    try {
        URL url = new URL("http://feeds.pcworld.com/pcworld/latestnews");

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(false);
        XmlPullParser xpp = factory.newPullParser();

        // We will get the XML from an input stream
        xpp.setInput(getInputStream(url), "UTF_8");

        /*
         * We will parse the XML content looking for the "<title>" tag which
         * appears inside the "<item>" tag. However, we should take in
         * consideration that the rss feed name also is enclosed in a
         * "<title>" tag. As we know, every feed begins with these lines:
         * "<channel><title>Feed_Name</title>...." so we should skip the
         * "<title>" tag which is a child of "<channel>" tag, and take in
         * consideration only "<title>" tag which is a child of "<item>"
         * 
         * In order to achieve this, we will make use of a boolean variable.
         */
        boolean insideItem = false;

        // Returns the type of current event: START_TAG, END_TAG, etc..
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {

                if (xpp.getName().equalsIgnoreCase("item")) {
                    insideItem = true;
                } else if (xpp.getName().equalsIgnoreCase("title")) {
                    if (insideItem)
                        Aheadlines.add(xpp.nextText()); // extract the
                                                        // headline
                } else if (xpp.getName().equalsIgnoreCase("link")) {
                    if (insideItem)
                        Alinks.add(xpp.nextText()); // extract the link of
                                                    // article
                }
            } else if (eventType == XmlPullParser.END_TAG
                    && xpp.getName().equalsIgnoreCase("item")) {
                insideItem = false;
            }

            eventType = xpp.next(); // move to next element
        }

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return Aheadlines;
}

protected void onPostExecute(List feed) {
    // TODO: check this.exception
    // TODO: do something with the feed
    super.onPostExecute(feed);

    // ListView itcItems = (ListView) findViewById(android.R.id.list);

    // Create a list adapter

    ArrayAdapter adapter = new ArrayAdapter(Main2.this,
            android.R.layout.simple_list_item_1, Aheadlines);
    // Set list adapter for the ListView
    Main2.setListAdapter(adapter);

}

//
public InputStream getInputStream(URL url) {
    try {
        return url.openConnection().getInputStream();
    } catch (IOException e) {
        return null;
    }
}
安德罗斯

这是因为您的AsyncTaskGetRSS不是Main2的内部类。

您必须创建一个内部类(因此,基本上,您只需要{在声明GetRSS类之前删除一个即可。}当然,在文件末尾添加一个即可

这样,您的GetRSS类将成为内部类,而Main2将进入其范围。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

MoviePy VideoFileClip实例没有属性“阅读器”

在没有pdf阅读器的应用内显示pdf

范围内没有封闭的...类型的实例

具有桌面警报的RSS阅读器

与 Google 阅读器同步的 RSS 阅读器?

缓存页面的RSS阅读器

用Java编写RSS阅读器

Java-罗马RSS阅读器?

PHP中的XML(RSS阅读器)

具有封闭阅读器应用程序的NFC卡仿真

AttributeError:“模块”对象没有属性“阅读器”

有没有办法在福昕阅读器中为 pdf 书签创建 Windows 快捷方式?

错误:无法访问类型为Main的封闭实例。必须使用Main类型的封闭实例来限定分配(egxnew A()wh

php中的简单RSS阅读器,具有连续滚动功能

没有可访问的foo类型的封闭实例。为什么?

没有可访问的MainRender类型的封闭实例

为阅读器实现monoid

RSS阅读器是否在localhost上读取XML?

尝试创建RSS阅读器时发生异常?

集成了Unity消息菜单的RSS阅读器?

如何编写Windows Phone 8.1的RSS阅读器?

RSS阅读器:UITableView显示数据的速度非常慢

可以跨计算机同步的RSS阅读器?

带选择(选项)框的RSS php阅读器

Android-扩展时出现“范围内没有'some.abstract.class.name'类类型的封闭实例”错误

javax.ws.rs.NotSupportedException:找不到类型为:class的消息正文阅读器

无法访问类型为...的封闭实例

按钮上没有可见的文本,但屏幕阅读器需要文本吗?

SCIP:没有输入文件<sample.txt>的阅读器