首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SimpleAdapter为空?

SimpleAdapter为空?
EN

Stack Overflow用户
提问于 2013-02-17 03:19:24
回答 1查看 225关注 0票数 0
代码语言:javascript
复制
package com.coltonnicotera.londontransitguide;

//bunch of imports

public class SchedulesActivity extends Activity {

    /** Called when the activity is first created. */
    List<Map<String, String>> routesList = new ArrayList<Map<String,String>>();

    String[] routesArray = new String[] {"01. Kipps Lane/Thompson Road", "02. Dundas", "03. Hamilton Rd", "04. Oxford East", "05. Springbank", "06. Richmond", "07. Wavell", "08. Riverside", "09. Whitehills", "10. Wonderland", "11. Southcrest", "12. Warncliffe South", "13. Wellington Road", "14. Highbury", "15. Westmount", "16. Adelaide", "17. Oxford West", "19. Oakridge", "20. Cherryhill", "21. Huron Heights", "22. Trafalgar", "23. Berkshire", "24. Baseline", "25. Kilally", "26. Jalna Blvd. West", "27. Fanshawe College", "28. Lambeth", "30. Newbold", "31. Orchard Park", "32. Windermere", "33. Proudfoot", "34. Medway", "35. Argyle", "36. Airport/Industrial", "37. Sovereign Road", "38. Stoney Creek", "39. Fanshawe West"};      

    public void onCreate(Bundle savedInstanceState) {
        initList();
        ListView lv = (ListView) findViewById(R.id.listView);    
        SimpleAdapter simpleAdpt = new SimpleAdapter(this, routesList, android.R.layout.simple_list_item_1, new String[] {"route"}, new int[] {android.R.id.text1}); 
/*LINE 63 */        lv.setAdapter(simpleAdpt);
    }

   private void initList() {
       for (int i = 0; i<=36; i++)
           routesList.add(createRoute("route", routesArray[i]));
    }

   private HashMap<String, String> createRoute(String key, String name) {
        HashMap<String, String> route = new HashMap<String, String>();
        route.put(key, name);
        return route;
    }
}

我的问题是在第63行有一个NullPointerException。我不确定这里到底什么是null。为了简单起见,我删除了所有的导入。R.id.listView也存在。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-17 03:21:33

您还没有设置为什么listview findViewbyId返回null...so的布局您需要在oncreate()中设置contentView,然后再实际获取listview ...like setContentView(R.layout.yourlayout)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14914140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档