Deepti M
07/12/2020, 9:29 PMif (lastWallpaperEngine != null && !lastWallpaperEngine!!.isPreview) {
}
Logs received in play-store...
java.lang.NullPointerException:
at android.service.wallpaper.WallpaperService$Engine.isPreview (WallpaperService.java:390)
at VideoWallpaperEngine.onSurfaceDestroyed (VideoWallpaperService.java:158)
Valentin Moscone
07/12/2020, 9:34 PMIf (null) is going to fail
Joost Klitsie
07/13/2020, 8:13 AMlastWallpaperEnging
is not null, but nullified just before you call !lastWallpaperEnging...
This could for example happen with async code, or perhaps by getting the value it will nullify it (I know that it is weird but in theory you can do that with kotlin)
Then you have indeed the case that lastWallpaperEnging
is not null, but the isPreview
variable. the best way to check this, is to use Kotlin as kotlin and not as Java. Meaning: you never write the old Java null check if (stuff != null)
but you write it as kotlin:
if (lastWallpaperEngine?.isPreview == false) {}
This will only return true if your value is not null and also false. It has a double null check inside, because if either lastWallpaperEngine
or isPreview
is null you are safe.Deepti M
07/13/2020, 3:22 PM