Android:SimpleAdapter错误

Android:SimpleAdapter错误,android,simpleadapter,Android,Simpleadapter,您好,为了在列表视图中显示一些通知,我使用了这个SimpleAdapter。这些通知位于ArrayListlocalist中。代码如下: SimpleAdapter adapter = new SimpleAdapter(this,localist, R.layout.rss_list_item,new String[] {"title","pubDate"},new int[] {R.id.title, R.id.pubDate }); final ListView lv = (Lis

您好,为了在列表视图中显示一些通知,我使用了这个SimpleAdapter。这些通知位于
ArrayList
localist中。代码如下:

SimpleAdapter adapter = new SimpleAdapter(this,localist, R.layout.rss_list_item,new String[] {"title","pubDate"},new int[] {R.id.title, R.id.pubDate });
    final ListView lv = (ListView) findViewById(android.R.id.list);
    lv.setAdapter(adapter);
protected Integer doInBackground(Void... params) {
        ArrayList<HashMap<String, String>> localist = new ArrayList<HashMap<String, String>>();
        String xml = ParseXMLmethods.getXML();
        Document doc = ParseXMLmethods.XMLfromString(xml);
        if (doc != null) {
        NodeList children = doc.getElementsByTagName("item");
        ZERO_FLAG = false;
        if (children.getLength() == 0) {
        ZERO_FLAG = true;
        publishProgress();
        }
        for (int i = 0; i < children.getLength(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) children.item(i);
        map.put("title", ParseXMLmethods.getValue(e, "title"));
        map.put("pubDate", ParseXMLmethods.getValue(e, "pubDate"));
        map.put("link", ParseXMLmethods.getValue(e, "link"));
        map.put("description",ParseXMLmethods.getValue(e, "description"));
        localist.add(map);

        }
问题是,它在这里向我显示了三个错误。第一个是在localist,它说“localist不能解析为变量”

第二个和第三个在

lv.setAdapter(adapter);
一个位于点上,表示“令牌上的语法错误,错位构造”,另一个位于括号内的适配器上,表示“令牌上的语法错误”适配器,此令牌后应为VariableDeclaratorId”。我认为第二个和第三个错误是由第一个错误引起的。你有什么办法解决这个问题吗?提前很多

编辑: localist在其他活动中声明和创建 代码如下:

SimpleAdapter adapter = new SimpleAdapter(this,localist, R.layout.rss_list_item,new String[] {"title","pubDate"},new int[] {R.id.title, R.id.pubDate });
    final ListView lv = (ListView) findViewById(android.R.id.list);
    lv.setAdapter(adapter);
protected Integer doInBackground(Void... params) {
        ArrayList<HashMap<String, String>> localist = new ArrayList<HashMap<String, String>>();
        String xml = ParseXMLmethods.getXML();
        Document doc = ParseXMLmethods.XMLfromString(xml);
        if (doc != null) {
        NodeList children = doc.getElementsByTagName("item");
        ZERO_FLAG = false;
        if (children.getLength() == 0) {
        ZERO_FLAG = true;
        publishProgress();
        }
        for (int i = 0; i < children.getLength(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) children.item(i);
        map.put("title", ParseXMLmethods.getValue(e, "title"));
        map.put("pubDate", ParseXMLmethods.getValue(e, "pubDate"));
        map.put("link", ParseXMLmethods.getValue(e, "link"));
        map.put("description",ParseXMLmethods.getValue(e, "description"));
        localist.add(map);

        }
受保护整数doInBackground(Void…params){
ArrayList localist=新的ArrayList();
String xml=ParseXMLmethods.getXML();
Document doc=ParseXMLmethods.XMLfromString(xml);
如果(doc!=null){
NodeList children=doc.getElementsByTagName(“项”);
零标志=假;
if(children.getLength()==0){
零标志=真;
出版进度();
}
for(int i=0;i
从您的评论中,我想我知道发生了什么。看起来您的
异步任务
与您的
适配器
在一个单独的文件中。有几种方法可以解决此问题。一种方法是在任务完成后使用
接口
适配器
中设置变量

用于为
异步任务创建
接口


更简单的方法是将
AsyncTask
设置为
适配器所在的内部类,并将
localist
设置为该类的成员变量,以便两者都可以访问该类。然后可以在
onPostExecute()中设置
适配器
列表视图

给我们看更多的代码。你在哪里定义和创建localist?@SimonSays这里是你唯一尝试使用
localist
的地方吗?@codeMagic是的,那是你唯一尝试清理项目的地方吗?我看到的这些看起来像是奇怪的错误。你的
列表视图和在哪里ode>Adapter
您在顶部发布的代码?仍然不起作用:/我可以给您发送我的代码,看看我是否做得正确吗?您是否将
localist
作为成员变量(在方法之外声明)?这就成功了!非常感谢您。我真的非常感谢您的帮助!