Skip to content

[2.0.0] java.lang.NullPointerException: null cannot be cast to non-null type android.view.ViewGroup #145

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

Closed
3 tasks done
efstathiosntonas opened this issue Feb 25, 2025 · 4 comments · Fixed by #146
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@efstathiosntonas
Copy link
Contributor

efstathiosntonas commented Feb 25, 2025

Before submitting a new issue

  • I tested using the latest version of the library, as the bug might be already fixed.
  • I tested using a supported version of react native.
  • I checked for possible duplicate issues, with possible answers.

Bug summary

Hi, just upgraded to 2.0.0 and got this in release mode on app boot:

java.lang.NullPointerException: null cannot be cast to non-null type android.view.ViewGroup
      	at com.lodev09.truesheet.TrueSheetDialog.getContainerView(TrueSheetDialog.kt:28)
      	at com.lodev09.truesheet.TrueSheetDialog.getContentView(TrueSheetDialog.kt:74)
      	at com.lodev09.truesheet.TrueSheetView.onAttachedToWindow$lambda$7(TrueSheetView.kt:181)
      	at com.lodev09.truesheet.TrueSheetView.$r8$lambda$LPseJVBVeSEffsJXW-1fD5ol-tc(Unknown Source:0)
      	at com.lodev09.truesheet.TrueSheetView$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
      	at android.os.Handler.handleCallback(Handler.java:991)
      	at android.os.Handler.dispatchMessage(Handler.java:102)
      	at android.os.Looper.loopOnce(Looper.java:232)
      	at android.os.Looper.loop(Looper.java:317)
      	at android.app.ActivityThread.main(ActivityThread.java:8787)
      	at java.lang.reflect.Method.invoke(Native Method)
      	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
      	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:871)

Library version

2.0.0

Environment info

info Fetching system and libraries information...
System:
OS: macOS 15.3.1
CPU: (20) arm64 Apple M1 Ultra
Memory: 401.20 MB / 64.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.18.2
path: ~/.nvm/versions/node/v20.18.2/bin/node
Yarn:
version: 4.6.0
path: /opt/homebrew/bin/yarn
npm:
version: 11.1.0
path: ~/.nvm/versions/node/v20.18.2/bin/npm
Watchman:
version: 2025.02.17.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /Users/stathis/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK:
API Levels:
- "31"
- "33"
- "34"
- "35"
Build Tools:
- 30.0.3
- 33.0.0
- 33.0.1
- 33.0.2
- 34.0.0
- 35.0.0
System Images:
- android-25 | Google APIs ARM 64 v8a
- android-27 | Google APIs ARM 64 v8a
- android-28 | Google APIs ARM 64 v8a
- android-29 | Google APIs ARM 64 v8a
- android-30 | Google APIs ARM 64 v8a
- android-31 | Google APIs ARM 64 v8a
- android-33 | Google APIs ARM 64 v8a
- android-34 | Google APIs ARM 64 v8a
- android-34 | Google Play ARM 64 v8a
- android-35 | Google Play ARM 64 v8a
- android-35 | Pre-Release 16 KB Page Size Google Play ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2024.2 AI-242.23726.103.2422.13016713
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.13
path: /usr/bin/javac
Ruby:
version: 3.2.2
path: /Users/stathis/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

Steps to reproduce

  1. Just upgrade to version 2.0.0 and build release.

Reproducible example repository

no-repo-sorry

@efstathiosntonas efstathiosntonas added the bug Something isn't working label Feb 25, 2025
@efstathiosntonas
Copy link
Contributor Author

@lodev09 smells like a race condition, sometimes the app boots sometimes it crashes on boot.

@efstathiosntonas
Copy link
Contributor Author

I think this fixed it, testing it now

@lodev09+react-native-true-sheet+2.0.0.patch

diff --git a/node_modules/@lodev09/react-native-true-sheet/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt b/node_modules/@lodev09/react-native-true-sheet/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt
index cf3e99a..b42aa3d 100644
--- a/node_modules/@lodev09/react-native-true-sheet/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt
+++ b/node_modules/@lodev09/react-native-true-sheet/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt
@@ -70,12 +70,12 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
   var backgroundColor: Int = Color.WHITE
 
   // 1st child is the content view
-  val contentView: ViewGroup
-    get() = containerView.getChildAt(0) as ViewGroup
+  val contentView: ViewGroup?
+    get() = containerView.getChildAt(0) as? ViewGroup
 
   // 2nd child is the footer view
-  val footerView: ViewGroup
-    get() = containerView.getChildAt(1) as ViewGroup
+  val footerView: ViewGroup?
+    get() = containerView.getChildAt(1) as? ViewGroup
 
   var sizes: Array<Any> = arrayOf("medium", "large")
 
@@ -196,7 +196,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
   }
 
   fun positionFooter() {
-    footerView.apply {
+    footerView?.apply {
       y = (maxScreenHeight - sheetContainerView.top - footerHeight).toFloat()
     }
   }
diff --git a/node_modules/@lodev09/react-native-true-sheet/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt b/node_modules/@lodev09/react-native-true-sheet/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt
index 90d4023..5627a42 100644
--- a/node_modules/@lodev09/react-native-true-sheet/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt
+++ b/node_modules/@lodev09/react-native-true-sheet/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt
@@ -178,8 +178,8 @@ class TrueSheetView(context: Context) :
 
     // Initialize content
     UiThreadUtil.runOnUiThread {
-      setContentHeight(sheetDialog.contentView.height)
-      setFooterHeight(sheetDialog.footerView.height)
+      sheetDialog.contentView?.height?.let { setContentHeight(it) }
+      sheetDialog.footerView?.height?.let { setFooterHeight(it) }
 
       if (initialIndex >= 0) {
         currentSizeIndex = initialIndex

@lodev09
Copy link
Owner

lodev09 commented Feb 25, 2025

@efstathiosntonas yep! that should fix it. If you don't mind submitting PR :)

@efstathiosntonas
Copy link
Contributor Author

fixed via #146

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants