Android Question (Solved)Recieving "java.lang.RuntimeException: Array not expected..."

Discussion in 'Android Questions' started by opus, Jun 2, 2015.

  1. opus

    opus Member Licensed User

    Hi I'm recieving a "java.lang.RuntimeException: Array not expected..." in this line:
    Code:
    If (MyList.Size=0 AND MyBoolean=FalseThen
    MyList is a (initialised) List of custom class objects
    MyBoolean is a Boolean
    This particular line is run a lot with no problem before the error occurs. Logging both variables (MyList.Size and MyBoolean) rigth before that line doesn't show any problem. However the problem is raised again.
    Where could I look elsewhere?
     
  2. fixit30

    fixit30 Active Member Licensed User

    You should try not using brackets.

    Code:
    If MyList.Size = 0 AND MyBoolean = False Then
     
  3. opus

    opus Member Licensed User

    Thanks forv the reply, however IMHO if that would be the reason an exception should have been raised before.

    I did some more tests.
    That line is within a Do..Loop which holds an DoEvents command. I figured that DoEvents neccessary because the line inside the If-statement starts a timer, which should do something.
    By changing the setup from using a Do..Loop with DoEvents to a second Timer, the error isn't showing.
    But WHY??????, I'm curious!
     
  4. fixit30

    fixit30 Active Member Licensed User

    Sorry, but without seeing more of your code it is impossible to say.
     
  5. opus

    opus Member Licensed User

    The code that causes the Problem:
    Code:
    Do Until MyBooleanB=True
      
    If (MyList.Size=0 And MyBooleanA=FalseThen 'the above posted exception is raised here!
         
           StartTimer 
    'This Sub fills MyList with items and starts a timer,
                            'after several runs of its _Tick-Routine the MyList gets its items removed and MyBooleanA is set to False
                          
      
    End If
      
    If CheckSomething=True Then
         MyBooleanB=
    True
       
    End If
    Loop
    since the exception isn't raised during the first Iteration nor at the same Iteration during several test-runs using the same Setup, I believe it could be a Problem caused by a race-condition between the Do..Loop and the Timer.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You cannot hold the main thread in a loop. It will not work. Instead you should continue the program logic from the timer event.
     
  7. opus

    opus Member Licensed User

    Tanks for the reply Erel. Yes I already figured that using Timers solely would work.
    Is there an explanation why it does not in a loop? I'm just curious.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    I don't know why you got this specific error message. For this I need to go over all the code. However almost all events, including the timer events will not fire while the main thread is busy. They will only fire when the main thread is free to process the message queue.

    Android will kill the process if the main thread is not processing the message queue for more than 5 - 10 seconds.
     
  9. opus

    opus Member Licensed User

    Thanks, that is just the explanation I was looking for.

    Closed!
     
Loading...