Android Question Error in code when deploy to android 5.1.1

Jose Luis Barajas

Member
Licensed User
Longtime User
Hi Friends!

I have a problem with mi project, when I deploy to Sony Xperia with android 5.1.1
The program gets the follow exception:

In the activity when initialize calendar, I get this error...
B4X:
Sub Activity_Create(FirstTime As Boolean)

    ' Coloca la zona horaria de mexico
    DateTime.SetTimeZone(-5)
   
    ListDays.Initialize
    ListDays.Add("06/01/2015")
    ListDays.Add("06/02/2015")
    ListDays.Add("06/03/2015")
    ListDays.Add("06/18/2015")
   
    Dim factor As Float
    factor = 0.50
   
    ' THIS LINE GETS ERROR ONLY ON ANDROID 5.1.1, WITH VERSION 4.x.x WORKS FINE!!!
    '*******************************************************************************
    CsCal.Initialize(Me, "CsCal" ,100%x, 100%y * 0.51, DateTime.Now, ListDays)

LogCat connected to: B4A-Bridge: Sony C6906
....
....
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (calendario) Create, isFirst = true **
java.lang.NullPointerException: locale == null

This error seems strange, because the same project deployed to any device with android 4.x.x works very well,
I hope some in this forum can help me!

I post and zip file with my project

I was using B4A 4.30
 

Attachments

  • zdemo_borrar.zip
    372.7 KB · Views: 117
  • IMG_4528_Sharpness_1.JPG
    IMG_4528_Sharpness_1.JPG
    66 KB · Views: 121

klaus

Expert
Licensed User
Longtime User
The attached modified version works on my Sony xperia z1 with Android version 5.1.1
I moved the declaration of Local As AHLocale from Main to the Class.
And you didn't initialize Local.
 

Attachments

  • zdemo_borrar_new.zip
    12 KB · Views: 124
Upvote 0

Jose Luis Barajas

Member
Licensed User
Longtime User
Hi Klaus, thanks for your Help, you are really a Master!

I have a doubt, why without your changes the code runs on android 4.x.x?

And also I like to know how you trap this error, so, Its possible that you teach us, for learning how to manage this kind of errors,
in order to develop more faster and not stay away trying and trying?

Muchas Gracias!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
When I first ran the program I got an error in this line in the CustomCalendar module:
Public NmFullday(7) As String : NmFullday = Main.Local.WeekDays
I found 'strange' that in the Class there is a reference to an object in Main.
Then, I was looking what kind of object Local was, where and how it was declared.
I saw that Local is an AHLocale object from the AHLocale library.
I saw that Local was not used in Main, so I moved the declaration to CustomCalendar.
It is no more good practice to set values (NmFullday = Main.Local.WeekDays in this case) in the Process_Globals, Class_Globals or Global routines so I moved these instructions from Class_Globals to Initialize.
Then, running the program, I got an error NullPointerExeption.
This error appears mainly when an object is not initialized.
I had a look at the help for the AHLocale library if there is an Initialize method.
I saw that AHLocale has Initialize methods, but no Local.Initialize in the code.
I added it and it works.

You should also look at the compiler Warnings in the Logs and correct the code accordingly. I know it's a test program so a part of the warnings are due to this fact, but others (for example missing variable type declaration) should be corrected.

I have a doubt, why without your changes the code runs on android 4.x.x?
I don't know why.
So I tested now your original code on my Asus tablet with Android version 4.2.1 and get the same error as with Android 5.1.1 on the xperia !?
 
Upvote 0

Jose Luis Barajas

Member
Licensed User
Longtime User
Hi Klaus,

Thanks for your reply, I need to see with more detail in the future, for trap the source of this kind of errors.
Anyway whit your help, now I can continue with my project.

Regards!
 
Upvote 0
Top