domoritz / open-mensa-android

Android OpenMensa Client, shows the meals for university canteens
44 stars 12 forks source link

Crash when selecting a favourite canteen #25

Closed gsauthof closed 9 years ago

gsauthof commented 9 years ago

I can reproduce the issue with the current 0.8 version on a Android 5 device (there installed via fdroid, because it is not available in the google play store) and on a Android 4.3 device (there installed via google play).

Steps to reproduce it:

  1. open APP
  2. refresh canteens (-> progress dialog shows 1/4 to 4/4)
  3. app requests to setup a favourite canteen
  4. ok -> preferences dialog is displayed
  5. tap on 'Favourite Canteens => 'Unfortunately, OpenMensa has stopped'

(step 2 is optional, app still crashes)

I've captured following stack trace via adb logcat:

D/Canteendroid(24905): Got favourites []
D/Canteendroid(24905): Update favourites: []
D/Canteendroid(24905): Refreshing favourite canteen list
D/Canteendroid(24905): Got favourites []
D/Canteendroid(24905): Update favourites: []
D/Canteendroid(24905): Got favourites []
D/Canteendroid(24905): Update favourites: []
D/Canteendroid(24905): Spinner items: []
D/Canteendroid(24905): Got favourites []
D/Canteendroid(24905): Update favourites: []
D/Canteendroid(24905): New Fragment requested 2
D/Canteendroid(24905): New Fragment requested 1
D/Canteendroid(24905): New Fragment requested 3
D/Canteendroid(24905): Got favourites []
D/Canteendroid(24905): Update favourites: []
D/Canteendroid(24905): Fetch canteens because storage is out of date or empty
D/Canteendroid(24905): Fetching from http://openmensa.org/api/v2/canteens?limit=50
D/Canteendroid(24905): Fetching from http://openmensa.org/api/v2/canteens?limit=50&page=2
D/Canteendroid(24905): Fetching from http://openmensa.org/api/v2/canteens?limit=50&page=3
D/Canteendroid(24905): Fetching from http://openmensa.org/api/v2/canteens?limit=50&page=4
D/Canteendroid(24905): Fetched 196 canteen items
D/Canteendroid(24905): Refreshing favourite canteen list
D/Canteendroid(24905): Got favourites []
D/Canteendroid(24905): Update favourites: []
D/Canteendroid(24905): Got favourites []
D/Canteendroid(24905): Update favourites: []
D/Canteendroid(24905): Spinner items: []
D/Canteendroid(24905): Got favourites []
D/Canteendroid(24905): Update favourites: []
D/Canteendroid(24905): Save state, flushed cache storage
D/AndroidRuntime(24905): Shutting down VM
E/AndroidRuntime(24905): FATAL EXCEPTION: main
E/AndroidRuntime(24905): Process: de.uni_potsdam.hpi.openmensa, PID: 24905
E/AndroidRuntime(24905): java.lang.NullPointerException: Attempt to invoke virtual method 'float java.lang.Float.floatValue()' on a null object reference
E/AndroidRuntime(24905):    at de.uni_potsdam.hpi.openmensa.api.preferences.SelectFavouritesPreference$1.distanceToCurrentLocation(SelectFavouritesPreference.java:91)
E/AndroidRuntime(24905):    at de.uni_potsdam.hpi.openmensa.api.preferences.SelectFavouritesPreference$1.compare(SelectFavouritesPreference.java:97)
E/AndroidRuntime(24905):    at de.uni_potsdam.hpi.openmensa.api.preferences.SelectFavouritesPreference$1.compare(SelectFavouritesPreference.java:88)
E/AndroidRuntime(24905):    at java.util.TimSort.binarySort(TimSort.java:261)
E/AndroidRuntime(24905):    at java.util.TimSort.sort(TimSort.java:204)
E/AndroidRuntime(24905):    at java.util.TimSort.sort(TimSort.java:169)
E/AndroidRuntime(24905):    at java.util.Arrays.sort(Arrays.java:2010)
E/AndroidRuntime(24905):    at java.util.Collections.sort(Collections.java:1883)
E/AndroidRuntime(24905):    at de.uni_potsdam.hpi.openmensa.api.preferences.SelectFavouritesPreference.initializeValues(SelectFavouritesPreference.java:88)
E/AndroidRuntime(24905):    at de.uni_potsdam.hpi.openmensa.api.preferences.SelectFavouritesPreference.showDialog(SelectFavouritesPreference.java:66)
E/AndroidRuntime(24905):    at android.preference.DialogPreference.onClick(DialogPreference.java:274)
E/AndroidRuntime(24905):    at android.preference.Preference.performClick(Preference.java:983)
E/AndroidRuntime(24905):    at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:214)
E/AndroidRuntime(24905):    at android.widget.AdapterView.performItemClick(AdapterView.java:300)
E/AndroidRuntime(24905):    at android.widget.AbsListView.performItemClick(AbsListView.java:1143)
E/AndroidRuntime(24905):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3044)
E/AndroidRuntime(24905):    at android.widget.AbsListView$3.run(AbsListView.java:3833)
E/AndroidRuntime(24905):    at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime(24905):    at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(24905):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(24905):    at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime(24905):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(24905):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(24905):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime(24905):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
gsauthof commented 9 years ago

Perhaps this is because the 4th canteens response (to http://openmensa.org/api/v2/canteens?limit=50&page=4) currently contains an entry with null coordinates?

I mean this entry:

 {"id": 192, 
  "name": "Gebze Y\u00fcksek Teknoloji Enstit\u00fcs\u00fc",
  "city": "Gebze/Kocaeli",
  "address": "Gebze Y\u00fcksek Teknoloji Enstit\u00fcs\u00fc Rekt\u00f6rl\u00fc\u011f\u00fc P.K141 41400 Gebze/KOCAEL\u0130",
  "coordinates": [null, null]},
domoritz commented 9 years ago

That could be it. I filed an issue. As far as I see, the API does not specify what values can be null.

cyroxx commented 9 years ago

Because of this issue, the app is currently unusable for me. I just installed it on a new device where I cannot select any canteen because of this error.

Is there a workaround for this? Or maybe this issue can be fixed inside the app? I mean, the data might not be correct according to the specification, but a simple null check on the canteen input data would avoid the app to crash because of a single faulty canteen. I'm thinking in terms of robustness here.

domoritz commented 9 years ago

Should be an easy fix, I believe. Unfortunately, I don't have the time to fix it right now but would be happy to merge a pull request and deploy a new version.

cyroxx commented 9 years ago

That is what I say. It would just require to check whether longitude or tatitude of the canteen is null, and if so, ignore it.

If you let me, I would even try to fix it on my own so that I have an incentive to set the development environment back up here ;)

domoritz commented 9 years ago

That would be excellent. I just need to push to the play store because I have the certificate and stuff.