WSDOT / wsdot-android-app

Source code for the WSDOT Android application
GNU General Public License v3.0
19 stars 12 forks source link

Amtrak Crashes When Rotating Device with No Destination #51

Closed loganSims closed 8 years ago

loganSims commented 8 years ago

Rotating the device from portrait to landscape while viewing a schedule with no destination selected causes the view to crash. If you have a destination selected it works as expected when rotating the device.

Trace from Version 3.5.2
java.lang.NullPointerException
at gov.wa.wsdot.android.wsdot.ui.amtrakcascades.AmtrakCascadesSchedulesDetailsFragment$
   ScheduleAdapter.getView(AmtrakCascadesSchedulesDetailsFragment.java:722)
at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
at android.widget.AbsListView.obtainView(AbsListView.java:2271)
at android.widget.ListView.makeAndAddView(ListView.java:1769)
at android.widget.ListView.fillDown(ListView.java:672)
at android.widget.ListView.fillFromTop(ListView.java:733)
at android.widget.ListView.layoutChildren(ListView.java:1608)
at android.widget.AbsListView.onLayout(AbsListView.java:2106)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4364)
at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:584)
at android.view.View.layout(View.java:13754)
loganSims commented 8 years ago

I think this line causes the null pointer exception.

loganSims commented 8 years ago

I think the problem is with toLocation. When there is no destination selected, toLocation is set to fromLocation in DepartingTrainsLoader(). toLocation is then used in onBindViewHolder() in the recycler adapter. On a configuration change (screen rotation) toLocation gets set back to "N/A" in onAttach(), is never changed to fromLocation in DepartingTrainsLoader() and is used by OnBindViewHolder() which causes problems.

loganSims commented 8 years ago

Trace from commit 680abd2df29068e904696ca00b0bc5c3fba83f5c

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String
gov.wa.wsdot.android.wsdot.shared.AmtrakCascadesScheduleItem.getScheduledDepartureTime()' 
on a null object reference
   at gov.wa.wsdot.android.wsdot.ui.amtrakcascades.AmtrakCascadesSchedulesDetailsFragment$
          ScheduleAdapter.onBindViewHolder(AmtrakCascadesSchedulesDetailsFragment.java:725)
   at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5217)
   at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5250)
   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4487)
   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
...