2013-02-16 15 views
0
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。我不确定到底什么是空的。为了简单起见,我删除了所有导入。 R.id.listView也存在。SimpleAdapter null?

回答

1

您没有设置你的布局,为什么ListView的findViewbyId返回null ...所以你需要做的是在OnCreate中(),设置内容查看竟让你的ListView ......这样setContentView(R.layout.yourlayout)

+0

这必须有前这是我第三次忘记这一点。谢谢! – nicocolton 2013-02-16 19:22:29

+0

现在我得到这个:02-16 19:22:39.482:E/AndroidRuntime(1074):android.app.SuperNotCalledException:Activity {com.coltonnicotera.londontransitguide/com.coltonnicotera.londontransitguide.SchedulesActivity}没有通过调用到super.onCreate() – nicocolton 2013-02-16 19:23:18

+0

是在您的onCreate(Bundle savedInstancestate)方法中调用super.onCreate() – Pragnani 2013-02-16 19:24:06