Reputation: 83
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;
}
}
My problem is that on line 63 there is a NullPointerException. I'm not sure what exactly is null here. I've removed all the imports for simplicity. R.id.listView also exists.
Upvotes: 0
Views: 236
Reputation: 20155
You have not set your layout that why listview findViewbyId returns null...so what you need to do is In oncreate() ,set contentView before actually getting your listview ...like this setContentView(R.layout.yourlayout)
Upvotes: 1