简体   繁体   English

Android模拟器上的ListView中未显示数据

[英]Data not being displayed in ListView on Android emulator

I've managed to get the back end working for an android app, where it parses an RSS Feed. 我设法让后端适用于android应用,该应用在其中解析RSS Feed。 However I'm having real trouble getting it to display on the GUI. 但是我很难让它显示在GUI上。 I've read many tutorials, and either I'm doing something nobody else is, or as more likely the case, I'm doing something silly, like not calling something somewhere. 我已经阅读了许多教程,或者我正在做别人没有做的事情,或者更有可能的是,我正在做一些愚蠢的事情,例如不在某处打电话。

The problem is, after some help for the guys who's already responded, I'm getting null pointer exceptions in my code. 问题是,在对已经做出响应的家伙进行了一些帮助之后,我的代码中出现了空指针异常。 I've posted teh errors below for you to take a look at. 我在下面发布了错误,供您查看。 The code hasn't changed vastly from where I've dumped it on codepad. 从我将其转储到键盘上以来,代码没有太大变化。

I'm parsing the XML using SAX if that makes a blind bit of difference. 我正在使用SAX解析XML,如果这会造成一点点差异。

I've dumped the pertinent files here in plain text, and sorry that they're in one massive bunch.... 我已将相关文件以纯文本格式转储到这里,很抱歉它们一大堆....

Code Dump of Stuff 东西的代码转储

I just can't figure out where i'm going wrong. 我只是不知道我要去哪里错了。 Many thanks for your time once more. 非常感谢您的宝贵时间。

The errors from catlog are as follows: 来自catlog的错误如下:

CatLogErrors CatLogErrors

    public class WelshboyActivity extends   Activity 
    setContentView(R.layout.main);
    in UpdateGui() ,

        if(feeds.size()!=0){

        ListView itemlist = (ListView) findViewById(R.id.list);   
        ArrayAdapter<BlogPost> adapter = new ArrayAdapter<BlogPost>(this, android.R.layout.simple_list_item_1, feeds);
        itemlist.setAdapter(adapter);

    }else{
         Log.d("TAG","feeds is empty ");
}

If you extend ListActivity and want to use your main.xml then you forgot to call: 如果扩展ListActivity并想使用main.xml则您忘记调用:

setContentView(R.layout.main);

in your onCreate() method(before the feeds = getFeed(feedSource); ). 在您的onCreate()方法中(在feeds = getFeed(feedSource); )。 Also if you plan to extend ListActivity then in your layout you must have a ListView element with the id: 另外,如果您打算扩展ListActivity那么在布局中,您必须具有ID的ListView元素:

android:id="@android:id/list"

Then in your updateGui method you don't have to find the list because the ListActivity will automatically find it as long as you have the above ID : 然后,在您的updateGui方法中,您不必找到列表,因为只要您具有上述IDListActivity就会自动找到它:

private void UpdateGui() {
        ArrayAdapter<BlogPost> adapter = new ArrayAdapter<BlogPost>(this, android.R.layout.simple_list_item_1, feeds);
        setListAdapter(adapter);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM