I am trying to write a parser that parses out HTML times for bus routes.
But im having a problem getting the list to show up with a while loop.
I if use
Content = extractor.BusRoutes.get(0);
Content = extractor.BusRoutes.get(1);
I can get them to show up in a list by using a text view in android, but I want a list.
I can get a list if i go
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, busroutearray));
But thats if i have an XML already populated with the items, which i cant use easily.
the loop i am doing now is
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<String> busroutearray = new ArrayList<String>();
int x = 0;
while(x > 37){
busroutearray.add(x, extractor.BusRoutes.get(x));
x++;
}
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, busroutearray));
I can not figure out why it wont display, is there a better way to do this? the “x” is the spot in the array from 0 to 37.
Here is the LogCat
02-08 16:45:27.222: D/dalvikvm(1882): GC_EXTERNAL_ALLOC freed 52K, 54% free 2487K/5379K, external 1596K/2108K, paused 46ms
02-08 16:45:32.320: D/AndroidRuntime(1882): Shutting down VM
02-08 16:45:32.320: W/dalvikvm(1882): threadid=1: thread exiting with uncaught exception (group=0x40015578)
02-08 16:45:32.324: E/AndroidRuntime(1882): FATAL EXCEPTION: main
02-08 16:45:32.324: E/AndroidRuntime(1882): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.taylordev.nextstop/com.taylordev.nextstop.BusRoutes}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.os.Looper.loop(Looper.java:123)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-08 16:45:32.324: E/AndroidRuntime(1882): at java.lang.reflect.Method.invokeNative(Native Method)
02-08 16:45:32.324: E/AndroidRuntime(1882): at java.lang.reflect.Method.invoke(Method.java:507)
02-08 16:45:32.324: E/AndroidRuntime(1882): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
02-08 16:45:32.324: E/AndroidRuntime(1882): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
02-08 16:45:32.324: E/AndroidRuntime(1882): at dalvik.system.NativeStart.main(Native Method)
02-08 16:45:32.324: E/AndroidRuntime(1882): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
02-08 16:45:32.324: E/AndroidRuntime(1882): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.Activity.setContentView(Activity.java:1657)
02-08 16:45:32.324: E/AndroidRuntime(1882): at com.taylordev.nextstop.BusRoutes.onCreate(BusRoutes.java:50)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-08 16:45:32.324: E/AndroidRuntime(1882): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
02-08 16:45:32.324: E/AndroidRuntime(1882): ... 11 more
You never enter in your loop because you have
x=0and then the set the condition in the while loop to x > 37 (which is false). Maybe you’ll want to try x < 37 to actually get in your loop.EDIT:
For that exception, your activity
BusRoutesprobably extendsListActivityand you set a different layout withsetContentView(), a layout that doesn’t have the properListViewelement. If you extendListActivityand set a different layout whith the methodsetContentView(), in that layout, you must have aListViewelement with the id :so that the android system can know which
ListViewelement to bind to theListActivity. If this doesn’t solve the exception please post the code for theBusRoutes, at least theonCreate()method.