Wootric / WootricSDK-Android

Android SDK for Wootric Survey Platform supporting NPS, CSAT and CES surveys
https://wootric.com
MIT License
15 stars 16 forks source link

Fragment is crashing on large screens - tablets and foldables #143

Open koncinar opened 7 months ago

koncinar commented 7 months ago

Our app is crashing on large devices (tablets and foldable) with the following stack trace:

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.setVisibility(int)' on a null object reference
  at com.wootric.androidsdk.views.SurveyFragment.onCreateView (SurveyFragment.java:161)
  at android.app.Fragment.performCreateView (Fragment.java:2505)
  at android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1303)
  at android.app.FragmentManagerImpl.addAddedFragments (FragmentManager.java:2463)
  at android.app.FragmentManagerImpl.executeOpsTogether (FragmentManager.java:2234)
  at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute (FragmentManager.java:2190)
  at android.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:2091)
  at android.app.FragmentManagerImpl$1.run (FragmentManager.java:742)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:223)
  at android.app.ActivityThread.main (ActivityThread.java:7943)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:603)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:947)

The crash happens as soon as the survey is started.

We configure Wootric in the following way:

Wootric.init(
  activity,
  "...",
  "..."
).apply {
  setScoreColor(com.wootric.androidsdk.R.color.wootric_score_color)
  setSurveyColor(our.R.color.wootrick_survey)
  setLanguageCode(Locale.getDefault().language)
  setProductName(activity.getString(R.string.wootric_productName))
  setRecommendTarget(activity.getString(R.string.wootric_recommendAudience))
  setCustomMessage(
    WootricCustomMessage().apply {
      this.followupQuestion = activity.getString(R.string.wootric_followUp)
    }
  )
  setSurveyCallback(object : WootricSurveyCallback {
    ...
  })

  setEndUserEmail(session.user.email)
  setEndUserExternalId(session.user.id.toString())
  setEndUserCreatedAt(getFirstUsageDate())
  setProperties(hashMapOf(...))
}
koncinar commented 7 months ago

Inspecting the stack trace and your code it seems that the SurveyFragment is expecting the LinearLayout with id In the layout/wootric_footer.xml:36 it's present: <LinearLayout android:id="@+id/wootric_powered_by" ... While in the same file for large devices layout-sw600dp/wootric_footer.xml:10 the same layout has a different id: <LinearLayout android:id="@+id/wootric_layout_powered_by" ...

Which then causes this code in the SurveyFragment.java:148 to return null and later cause a NPE. mPoweredBy = (LinearLayout) view.findViewById(R.id.wootric_powered_by);

Note that wootric_layout_powered_by is being used in SurveyLayoutTablet.java:261, so it can't simply be removed. mPoweredByLayout = (LinearLayout) findViewById(R.id.wootric_layout_powered_by);