bug: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
See original GitHub issueBug Report
Capacitor Version
Latest Dependencies:
@capacitor/cli: 3.5.1
@capacitor/core: 3.5.1
@capacitor/android: 3.5.1
@capacitor/ios: 3.5.1
Installed Dependencies:
@capacitor/cli: 3.3.4
@capacitor/core: 3.3.4
@capacitor/android: 3.3.4
@capacitor/ios: 3.3.4
Platform(s)
Android
Current Behavior
When trying to run getUserMedia and show camera preview the app crashes and the only log we get in Android Studio is bug: java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.graphics.Bitmap.getWidth()’
Expected Behavior
App not crashing but working properly
Code Reproduction
I couldn’t reproduce the issue on a mini app with the same code
Other Technical Details
I found the issue and a fix for it, so just writing it down for the capacitor team or anyone else experiencing this problem. The fix I did was add
@Override
public Bitmap getDefaultVideoPoster() {
if (super.getDefaultVideoPoster() == null) {
return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
} else {
return super.getDefaultVideoPoster();
}
}
in BridgeWebCustomClient.java Line 84 (capacitor/src/main/java/com/getcapacitor/BridgeWebCustomClient.java)
This adds a black bitmap if there is no default video poster. I also tried this return BitmapFactory.decodeResource(bridge.getContext().getResources(), R.drawable.ic_transparent);
while importing R as import com.getcapacitor.android.R;
and this resulted in the same error which showed me that your ic_transparent (that you probably use if there is no default video poster) is crashing the app with the error.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top GitHub Comments
Thank you @PrabhatSuprdaily, we are indeed using the plugin diagonstic with version ^6.0.2 (which probably installed a newer version and we started to have problems). I’ll implement the version changes now.
@DanaStefanoska We also faced this issue in our project. We are having a dependency of ‘cordova.plugins.diagnostic’. With this library if we use version 6.0.0 - 6.0.3, it uses internally androidx.appcompat:appcompat with auto upgrade. And androidx.appcompat:appcompat has some compatibility issue with cordova sharing resources like camera in the later versions. In the earlier version or later ones ‘cordova.plugins.diagnostic’ have specified the exact version of androidx.appcompat:appcompat. PS: Please check your package-lock.json as well that the ‘cordova.plugins.diagnostic’ version is not between 6.0.0 - 6.0.3. @DanaStefanoska thanks for the temporary fix earlier.