Android Question Error with text animation

anaylor01

Well-Known Member
Licensed User
Longtime User
I get an error on this piece of code
selp.left = selp.left + 5dip
in the below sub routine. The error is below the code.
What I think the problem is is that the code is in the loop and then the view/Label is removed. SO how can I test to make sure the view/Label is still valid so this doesn't happen? Any ideas?
B4X:
Sub doanimation(selp As Label)
lab.Initialize("")
If lblAnswer.Visible = True Then
If lblTimer.Text >1 Then
            Do Until selp.left = lv.Width - 120dip
                selp.TextColor = Rnd(Colors.Black, Colors.White)
                selp.left = selp.left + 5dip
                selp.TextSize = selp.TextSize - 1.99dip
                selp.Width = selp.Width -1.9dip
               
                DoEvents
            Loop
            End If
        End If
End Sub
java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.ViewParent.requestLayout()' on a null object reference
 

JordiCP

Expert
Licensed User
Longtime User
I would protect some "dangerous" parts in your code

B4X:
...
Do Until selp.left >= lv.Width - 120dip   '<--- you are adding 5dip each time. So perhaps you never reach the "=" because it gets bigger.
  selp.TextColor = Rnd(Colors.Black, Colors.White)
  selp.left = selp.left + 5dip
  if selp.TextSize>1.99dip then selp.TextSize = selp.TextSize - 1.99dip  '<-- avoid negative values
  if selp.Width>1.9dip then selp.Width = selp.Width -1.9dip  '<--- avoid negative values
  DoEvents
Loop
...
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
What does this error mean? java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.ViewParent.requestLayout()' on a null object reference
I am thinking it means the view is no longer loaded.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
are you trying to zoom out the label? why are u doing it in a do...loop ?

why not just use x.setlayoutanimated ? or a timer?
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
Here is the error that happens on this line of code:selp.left = selp.left + 5dip
java.lang.NullPointerException
at anywheresoftware.b4a.objects.ViewWrapper.setLeft(ViewWrapper.java:172)
B4X:
Sub doanimation(selp As Label)
lab.Initialize("")
If lblAnswer.Visible = True Then
If lblTimer.Text >1 Then
Do Until selp.left >= lv.Width - 120dip   '<--- you are adding 5dip each time. So perhaps you never reach the "=" because it gets bigger.
    If lblPointFlash.Visible = True Then
  selp.TextColor = Rnd(Colors.Black, Colors.White)
If selp.Left < lv.Width Then
      selp.left = selp.left + 5dip
      End If
  If selp.TextSize>1.99dip Then selp.TextSize = selp.TextSize - 1.99dip  '<-- avoid negative values
  If selp.Width>1.9dip Then selp.Width = selp.Width -1.9dip  '<--- avoid negative values
  End If
  DoEvents
Loop

            End If
        End If
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Firstly .. you have been asked twice to edit the thread title. If you are unsure how to , you could have asked.
At the top right hand side of thread ...

Capture.PNG


As for your error ... the posted code ran OK here , but it could be other unknown factors that attribute to the error .
Posting a small test project might be the way to go ...
 
Upvote 0

anaylor01

Well-Known Member
Licensed User
Longtime User
I didn't see about editing the Title. I did that. It seems to have something to do with either the label being uninitialized or running out of space. I just can't figure out which.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
As already mentioned here try to copy the problematic code and creat a small project that includs the relevant code and that u can reproduce the error from that small project and upload it here.

It will make your and our life simpler.
 
Upvote 0
Top