0

I have a void like this:

public static void checkStateSignal(final int counter) {
    for (int l = 0; l < counter; l += 10) {
        if (counter - l < 9) {

            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                ArraySignal.LoggerStatus.get(counter) = separated[1];
                }
            },150);
        } 
    }
}

in which ArraySignal is a class and Loggerstatus is an Arraylist. I get an error on

ArraySignal.LoggerStatus.get(counter) = separated[1];

which is variable expected. So for some reason a final variable is not a variable and ArrayList.get doesn't want to get at a value position instead of a variable position which seems very illogical to me since you can get at a constant. Am i missing something? Also a solution for the problem would be very welcome.

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
dec0yable
  • 87
  • 13

3 Answers3

1

This is because you are using the accesor .get(index) for the ArrayList and that return a value, you need to use the .add(index,elem) to add an element at the given position. Check this link to look around Add object to ArrayList at specified index

Community
  • 1
  • 1
crgarridos
  • 8,758
  • 3
  • 49
  • 61
  • What i'm trying to do is setting the string in that index to a certain value. not adding a new one seems kind of redundant to add and then remove the previous one – dec0yable Apr 05 '16 at 10:41
  • oh, apparently there's a set function which I can use to set that String. Didn't know that. Was searching in the wrong direction, Thank you. – dec0yable Apr 05 '16 at 10:54
0

You can define a new class:

Class NewRunnable extends Runnable
{
   public int counter;
   public NewRunnable(int _counter)
   {
       counter = _counter;
       super();
   }
}

and then use that in your code like:

handler.postDelayed(new NewRunnable(counter) {
                @Override
                public void run() {
                String[] separated;
                ArraySignal.LoggerStatus.get(counter) = separated[1];
                }
            },150);
Pooya
  • 6,083
  • 3
  • 23
  • 43
0
ArraySignal.LoggerStatus.get(counter) = separated[1]

I think the issue is, you are trying to set value to a function

Nitesh
  • 3,868
  • 1
  • 20
  • 26