Object should first be initialized (List)

BowTieNeck

Member
Licensed User
Longtime User
I've attached a zip of a project I'm having trouble with, hoping you can help.
The app uses a csv file to hold a list of lottery numbers. A list in the Main Activity is refreshed from the csv file in the Main Resume event.
An Activity called EditTickets looks at this list in its Resume event.
In the Emulator this works fine but using the app on my Galaxy S2 I get -
An error has occurred in sub: edittickets_activity_resume (java line: 319)
java.lang.RuntimeException: Object should first be initialized (List). Continue?
and there are Yes/No buttons.
If I press No everything continues as if nothing had happened!
Any ideas?

By the way, line 319 of the java looks like this:
anywheresoftware.b4a.keywords.Common.Log("EditTickets.Resume Main.TicketList.Size = "+BA.NumberToString(mostCurrent._vvvvvvvvvvvvvv0._vvvvvv5.getSize()));

Thanks,
Chris
 

Attachments

  • uklottochecker.zip
    28.8 KB · Views: 176
  • Like
Reactions: yge

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I wonder how closely related a list is to a map? I had a piece of code last week that was running fine. I noticed when updating it to do more that I wasn't even Initializing the map and it was operating perfectly fine. I added the Initialize, but it still got me curious as to what exactly it does. If I were to guess I'd say adding items to it must do some type of initialize. Or, it could be that it is a bug that could cause weird behavior like this, and I should have been required to Initialize it....
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I had to delete the ad code too along with the xml since I don't use that library. I don't see how that is related to the error though. It ran fine on my end. Looking at the code you have an IF that either loads from CSV or Initialize. Assuming LoadCSV always returns an initialized list it should be fine. What happens if there is an error reading the list or the file isn't empty but contains invalid data or a single space? You may want to just Initialize the list either way and LoadCSV if file is fine. May even try an isInitialized test after LoadCSV whichever way it is loaded.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I confirm this error has nothing to do with adView, since I had it removed before running. I tested the app and this initialization error occurs time to time.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
ok, got it. The problem is with main.BackButtonPressed.
When you click 'back' in your main activity, you exit the app, that's ok. BUT android doesn't always kill the process. Thus, when you go to 'KeyBoard' and the boolean backButtonPressed is true, then you perform an exitApp. This doesn't seem to have the desired results, and you get back to the editTickets activity at its resume event. Now, remember that you've just exited your app, so list is not found (not initialized) causing this error.
My suggestion (and I think Erel, Klaus and other friends here, would agree): When you start a new activity, close the previous one with activity.finish. This way, you will not have the need to use an exitApplication which can cause undesired effects as the error that occurs in your code right now. Personally, I had also initialization problems in a app I was developing, but when I did this, such errors completely disappeared. Hope this helps.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi mc73,
I agree with you.
The management to exit the program looks strange.
I could also produce the error when rerunning the program and running the KeyBoard activity.
Chris should explain exactly how he wants to exit the program.

Best regards.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Hi mc73,
I agree with you.
The management to exit the program looks strange.
I could also produce the error when rerunning the program and running the KeyBoard activity.
Chris should explain exactly how he wants to exit the program.

Best regards.
Hello, Klaus.
I remember, some time ago, I suggested the use of such a boolean flag to another friend, here in this forum. It was about having activities not exiting when a startActivity was performed, so since our friend was insisting to keep the exitApplication, I suggested the use of this flag. Seeing the app here, I cannot figure out why we should keep this flag. But surely, our friend will remember what it was all about, and perhaps he has his reasons to do it :)
 
Upvote 0

BowTieNeck

Member
Licensed User
Longtime User
I've now removed the BackButtonPressed boolean and added Activity.Finish before each StartActivity. Everything seems to be working fiine now.

Many thanks to everybody for helping out with this.

:sign0098:
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
object should first be initialized (RadioButton)

Hi,

I got the following error :object should first be initialized (RadioButton)
Can anybody tell me how can solve it ?
I got this message only for radiobuttons when i change the orientations (if the apps start on portrait is ok after the rotation no), the rest of the components are behave ok.

Bellow you can see a part of my code :

Sub Globals
.......
Dim rdall As RadioButton
Dim rdactiv As RadioButton
Dim rdinactiv As RadioButton
.........
End Sub

Sub Activity_Resume
resize
End Sub

Sub resize
...........................
rdall.Width =pnlcamp.Width /3
rdall.Left =pnlcamp.Left
rdactiv.Width =pnlcamp.Width /3
rdactiv.Left =rdall.Width
rdinactiv.Width =pnlcamp.Width/3
rdinactiv.Left =rdall.Width + rdactiv.Width
...................
End Sub

The script in designer is :
rball.Top =btnSalveaza.Bottom +2dip
rball.Height =40dip
rball.Left =pnlcamp.Left
rball.Width =pnlcamp.Width /3

rbactiv.Top =btnSalveaza.Bottom +2dip
rbactiv.Height =40dip
rbactiv.Width =pnlcamp.Width /3
rbactiv.Left = rball.Width +1dip

rbinactiv.Top = btnSalveaza.Bottom +2dip
rbinactiv.Height =40dip
rbinactiv.Width =pnlcamp.Width /3
rbinactiv.Left = rbactiv.Right +1dip
rbinactiv.Right = pnlcamp.Right
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi Klaus ,

I couldn't upload the entire project because of archive size. Attached you can find the form that i have the problem.

Thank you
 

Attachments

  • Evidenta.zip
    61.5 KB · Views: 181
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi Klaus ,

Again thank you for previous help , but now i have another problem , for example : if i fill some fields in portrait orientation then i rotate the tab all fields became empty and i must fill again. Haw can i solve this problem ?

Thank you.
 
Upvote 0
Top