Object should first be initialized (ImageView)

QLogic

Member
Licensed User
Longtime User
Greetings,

I'm getting a weird error when playing around with my program. As I keep going through different layouts on my program, once in a while the error indicated in the title will show up. I have put the imageviews directly in the designer, and I am not initializing it in the code. But what happens is that when I cycle through the various layouts in my program, the error above comes up.

I am using Version 2.22 B4A. If you need to see the code, I can email it to you as the attachment size on these forums won't be large enough.

Thanks.
 

QLogic

Member
Licensed User
Longtime User
Greetings Erel,

Thanks for getting back to me. The layout that I am loading does include this view for sure. All the layouts I have with the exception of 2 or 3 have an imageview that they use. Mainly for the banner at the top of the layout. You basically have to play around with the app to generate the error because it is rather random.

Thanks.
 
Upvote 0

QLogic

Member
Licensed User
Longtime User
I think I might have figured it out. And it has to do with how I handle the back button. I'm wondering if you can confirm.

I should remove all views from the current activity and finish it, then start the next activity correct?. I.E.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
   If KeyCode = KeyCodes.KEYCODE_BACK Then
      StartActivity("AdaptersList")
      Activity.Finish
   End If
End Sub

versus

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
   If KeyCode = KeyCodes.KEYCODE_BACK Then
      Activity.RemoveAllViews
      Activity.Finish
      StartActivity("AdaptersList")
   End If
End Sub
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
There's not need to do this:
B4X:
StartActivity("AdaptersList")

Unless you finished the "AdaptersList", just by hitting the BACK button on your device it will return to the previous activity.
 
Upvote 0

QLogic

Member
Licensed User
Longtime User
Hmmm, then maybe Erel should answer this, it might be a bug, I really don't know.

I think I fixed it though. I'm having another co-worker try to break the code before I update the play store. By doing the below, I think I'm clearing memory properly and starting the activity fresh so the initialization error doesn't come up:

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
   If KeyCode = KeyCodes.KEYCODE_BACK Then
      Activity.RemoveAllViews
      Activity.Finish
      StartActivity("HPPortal")
   End If
End Sub
 
Upvote 0

air cover

Member
Licensed User
Longtime User
Greetings,

I'm getting a weird error when playing around with my program. As I keep going through different layouts on my program, once in a while the error indicated in the title will show up. I have put the imageviews directly in the designer, and I am not initializing it in the code. But what happens is that when I cycle through the various layouts in my program, the error above comes up.

I am using Version 2.22 B4A. If you need to see the code, I can email it to you as the attachment size on these forums won't be large enough.

Thanks.
Just as a historical reference, I get the above running my code on old Android 2.2.1, but the same code runs fine on Android 4.4.2.
 
Upvote 0
Top