Android Question playstore : error pre-launch report - java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA fr.lyzo.main.activityBA'

voxel

Member
Licensed User
Hello,
I just put my app (with android 14) on the store in closed test and I have this pre-launch report. My app works well on different phones, it's strange. Could this be a "false" error from the store?

B4X:
Exception java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA fr.lyzo.main.activityBA' on a null object reference
  at fr.lyzo.main$ResumableSub_Activity_Create.resume (main.java:1066)
  at anywheresoftware.b4a.BA.checkAndRunWaitForEvent (BA.java:275)
  at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:215)
  at anywheresoftware.b4a.keywords.Common$12.run (Common.java:1212)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:201)
  at android.os.Looper.loop (Looper.java:288)
  at android.app.ActivityThread.main (ActivityThread.java:7870)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)

Thank for you help
 

walterf25

Expert
Licensed User
Longtime User
Looks like something was not Initialized maybe?

Does that report tell you if it's only a specific device this is happening? we need more context.
 
Upvote 0

voxel

Member
Licensed User
Hello,
The application crashes on 1 device only on the pre-launch report:
Model name: Small Desktop (x86) (virtual)
Android version: Android 12L (SDK 32)

Looking at the screenshots, I think the crash occurs during a file download (in progress) and maybe then the file save/unzip operations.
Hard to identify the cause of the problem with the trace.

A snippet of my code :

B4X:
                telecharge.Initialize("",Me)
                telecharge.Download(urlbdd)
                MessageInit.Text="Veuillez patienter..."&CRLF&"Téléchargement des données"
                Wait For (telecharge) JobDone(telecharge As HttpJob)
                
                If telecharge.Success Then
                    MessageInit.Text="Installation des données"
                    Dim out As OutputStream = File.OpenOutput(File.DirInternal, "bdd.zip", False)
                    File.Copy2(telecharge.GetInputStream, out)
                    out.Close
                    MessageInit.Text="Vérification des données"
                    
                    Dim Var() As Byte = "pass".GetBytes("ISO-8859-1")
                    Arc.DecryptZipWithArray(Var, False)
                    Arc.UnZip(File.DirInternal & "/bdd.zip", File.DirInternal,"Archiver")
                    File.Delete(File.DirInternal,"bdd.zip")
                    
                    telecharge.Release
 
Upvote 0

voxel

Member
Licensed User
I just did a test by installing the same emulator (Small Desktop - Android12) in android studio and my app works fine. Strange.
 
Last edited:
Upvote 0

asales

Expert
Licensed User
Longtime User
This is an emulator using by Google in test.
I saw that the emulators and device using in this tests causes errors that not happens in another devices.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Are you running that snippet in Activity_Create? If so then I would put it in Activity_Resume at the very least. Having that WaitFor in Activitity_Create will cause Activity_Resume to run immediately before returning to complete the rest of Activity_Create. This is not normally a 'good thing'.
 
Upvote 0

voxel

Member
Licensed User
Hello,
All my code is in Activity_Create. When launching my app, I download a file (splash screen waiting) and then the app can be used when the download is finished. I thought that the onResume executes when the onCreate code is finished?
Should I put most of my code in the onResume? The "NullPointerException" corresponds to this problem? Currently I don't have any code in the onResume
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
I thought that the onResume executes when the onCreate code is finished?
Not if you have a WaitFor in Activity_Create. B4A calls Activity_Create then Activity_Resume, one after the other. If you wait in Activity_Create then, as it always does, immediately exits that Sub and in this case then runs Activity_Resume. You need to analyse the actual sequence of code execution when you use WaitFor in a Sub.

Should I put most of my code in the onResume
Not necessarily, but as I said you need to look at the actual code execution sequence in your particular app. I don't know if that is the problem here but it might contribute to it.
 
Upvote 0

voxel

Member
Licensed User
Hello, Thank you for your advice. By putting almost all the code in the onResume, the app works well (but I have not republished it on the store). The download when launching the app takes around 10 seconds (display of a splashscreen) then I display a layout. I will test several hypotheses.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…