0

I am trying to fill in my ListView using an arraylist I already have filled out in my system.

Here is the OnCreate code that is in the ListActivity:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_view_test);

    history = new History(context);

    reportListView = (ListView) findViewById(R.id.reportListView);

    ArrayList<String> al = new ArrayList<String>(); 
    al=history.getHistory(DatabaseAdapter.RUNNER_HISTORY_TABLE).activityDate;
    final ArrayAdapter<String> ad;
    ad = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,al);
    reportListView.setAdapter(ad); //exception here


}

Here is the relevant xml code for the layout file:

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ListView
        android:id="@+id/reportListView"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center" >
    </ListView>

</LinearLayout>

Here is the log:

 05-13 18:45:51.216: E/AndroidRuntime(19107): FATAL EXCEPTION: main
 05-13 18:45:51.216: E/AndroidRuntime(19107): Process: com.example.jfitnessfunctiontester, PID: 19107
 05-13 18:45:51.216: E/AndroidRuntime(19107): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jfitnessfunctiontester/activities.ReportListViewActivity}: java.lang.NullPointerException
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.app.ActivityThread.access$800(ActivityThread.java:135)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.os.Handler.dispatchMessage(Handler.java:102)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.os.Looper.loop(Looper.java:136)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.app.ActivityThread.main(ActivityThread.java:5017)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at java.lang.reflect.Method.invokeNative(Native Method)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at java.lang.reflect.Method.invoke(Method.java:515)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at dalvik.system.NativeStart.main(Native Method)
 05-13 18:45:51.216: E/AndroidRuntime(19107): Caused by: java.lang.NullPointerException
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at activities.ReportListViewActivity.onCreate(ReportListViewActivity.java:41)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.app.Activity.performCreate(Activity.java:5231)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
 05-13 18:45:51.216: E/AndroidRuntime(19107):   ... 11 more

Thanks!

theJuls
  • 6,788
  • 14
  • 73
  • 160

1 Answers1

0

Figured it out after for some reason my exception changed into "RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'" for some reason

Found the solution on this other thread: RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

Community
  • 1
  • 1
theJuls
  • 6,788
  • 14
  • 73
  • 160