Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE in MyCoursesFragment when requesting course content #207

Open
abhijeetviswa opened this issue Jun 8, 2020 · 0 comments
Open

NPE in MyCoursesFragment when requesting course content #207

abhijeetviswa opened this issue Jun 8, 2020 · 0 comments
Assignees

Comments

@abhijeetviswa
Copy link
Member

Here is the error log from v1.6.0:

java.lang.NullPointerException: 
  at helper.UserAccount.getToken (UserAccount.java:40)
  at helper.CourseRequestHandler.getCourseData (CourseRequestHandler.java:166)
  at crux.bphc.cms.fragments.MyCoursesFragment.updateCourseContent (MyCoursesFragment.java:283)
  at crux.bphc.cms.fragments.MyCoursesFragment.access$400 (MyCoursesFragment.java:46)
  at crux.bphc.cms.fragments.MyCoursesFragment$5.onResponse (MyCoursesFragment.java:258)
  at crux.bphc.cms.fragments.MyCoursesFragment$5.onResponse (MyCoursesFragment.java:251)
  at helper.CourseRequestHandler$1.onResponse (CourseRequestHandler.java:92)
  at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run (ExecutorCallAdapterFactory.java:70)
  at android.os.Handler.handleCallback (Handler.java:883)
  at android.os.Handler.dispatchMessage (Handler.java:100)
  at android.os.Looper.loop (Looper.java:214)
  at android.app.ActivityThread.main (ActivityThread.java:7695)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:516)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)

At MyCoursesFragment.java:279, a new CourseRequestsHandler instance is being created, which requires a Context. It's probable that by the time the the method is called, the Activity dies for whatever reason. There are two ways to deal with this:

  1. Refactor the fragment (and similar fragments) to use a single CourseRequestHandler, created when the fragment is created. Cache any information instead of instantiating SharedPreferences in UserAccount's getters everytime.
  2. Use an Application context instead of an Activity context inside UserAccount.

Initial impressesions: I think both of them should be done. A refactor of CourseRequestHandler (if need be) might be beneficial. And, an Application context is enough for SharedPreference. It isn't required to couple that with a particular activity.

@abhijeetviswa abhijeetviswa self-assigned this Jun 8, 2020
@abhijeetviswa abhijeetviswa added this to the v1.7.0-beta.2 milestone Jun 19, 2020
@abhijeetviswa abhijeetviswa removed this from the v1.7.0-beta.3 milestone Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant