Program compiles but do not autoformat

Hello there! I am writing quite a long code, and until now I had no such weird issues. But since last modification, I can compile the code, but not autoformat it. When I [ch63743]+T it says this:

java.lang.ArrayIndexOutOfBoundsException: 1024
      at processing.app.tools.AutoFormat.run(AutoFormat.java:523)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
java.lang.ArrayIndexOutOfBoundsException: 1024
      at processing.app.tools.AutoFormat.run(AutoFormat.java:523)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Can someone help me with this, please? What does it mean? I am a very newbie and I quite don't get it... I found something similar on this thread, but it wasn't exactely this case... http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1196533515

Post your Sketch. Please use code tags (# button above the edit window).

Work thru your ()s & {}s, if there is serious enough mismatch I have seen it do weird things like that. If your put the vertical cursor just to the right of a ) or }, the mating side should highlight. Once you have the cursor in place, leave it there and use the vertical scroll bar to move back thru your sketch.

I went throug the curly and round brakets, and all seemed fine…
This is the code that gives me problems:

if(result_mux4051OneInPin[0] < threshold && result_mux4051OneInPin[1] < threshold && result_mux4051OneInPin[2] < threshold && result_mux4051OneInPin[3] < threshold && result_mux4051OneInPin[4] < threshold && result_mux4051OneInPin[5] < threshold && result_mux4051OneInPin[6] < threshold && result_mux4051OneInPin[7] < threshold && result_mux4051TwoInPin[0] < threshold && result_mux4051TwoInPin[1] < threshold && result_mux4051TwoInPin[2] < threshold && result_mux4051TwoInPin[3] < threshold && result_mux4051TwoInPin[4] < threshold && result_mux4051TwoInPin[5] < threshold && result_mux4051TwoInPin[6] < threshold && result_mux4051TwoInPin[7] < threshold && result_mux4051ThreeInPin[0] < threshold && result_mux4051ThreeInPin[1] < threshold && result_mux4051ThreeInPin[2] < threshold && result_mux4051ThreeInPin[3] < threshold && result_mux4051ThreeInPin[4] < threshold && result_mux4051ThreeInPin[5] < threshold && result_mux4051ThreeInPin[6] < threshold && result_mux4051ThreeInPin[7] < threshold && result_mux4051FourInPin[0] < threshold && result_mux4051FourInPin[1] < threshold && result_mux4051FourInPin[2] < threshold && result_mux4051FourInPin[3] < threshold && result_mux4051FourInPin[4] < threshold && result_mux4051FourInPin[5] < threshold && result_mux4051FourInPin[6] < threshold && result_mux4051FourInPin[7] < threshold ){
    someButtonsON = false;
  }

I know it’s a very bad way to write it, but I didn’t know how to make it elseway :’(…

I know it’s a very bad way to write it, but I didn’t know how to make it elseway

For one thing, it’s OK to have carriage returns anywhere in the statement. After each &&, put a carriage return.

Another thing to do is to set a flag to false. Then, invert the logic and use a for loop to set the flag to true, and break out of the loop whenever the condition is not true.

boolean someButtonsOn = false;
for(int i=0; i<10; i++)
{
  if(result_mux4051OneInPin[i] > threshold ||
     result_mux4051TwoInPin[i] > threshold ||
     result_mux4051ThreeInPin[i] > threshold ||
     result_mux4051FourInPin[i] > threshold )
  {
     someButtonsOn = true;
     break;
  }
}
// someButtonsOn is true if ANY button was pressed

So you want ALL these readings to be under threshold to make someButtonsON = false?
Or do you want ANY of them to be under threshold to make someButtonsON = false?

&& means each comparison must be met to satisfy the IF
|| would satisfy the IF when any comparison is met.

If your logic is as you want it, then you could try putting each comparison in ( )s also.
if( (comparison 1) && (comparison 2) && …) {some… }

Or rearrange the testing. You could skip the remaining comparsons once one was met also if performance is important:

if (comparison 1 is met) {
someButtonsON = false;
goto flag_met_point;}
if (comparison 2 is met) {
someButtonsON = false;
goto flag_met_point;}
:
:
if (comparison 32 is met) {
someButtonsON = false;}

flag_met_point:
// continue from here
if (
result_mux4051OneInPin[0] < threshold 
&& result_mux4051OneInPin[1] < threshold 
&& result_mux4051OneInPin[2] < threshold 
&& result_mux4051OneInPin[3] < threshold 
&& result_mux4051OneInPin[4] < threshold 
&& result_mux4051OneInPin[5] < threshold 
&& result_mux4051OneInPin[6] < threshold 
&& result_mux4051OneInPin[7] < threshold 
&& result_mux4051TwoInPin[0] < threshold 
&& result_mux4051TwoInPin[1] < threshold 
&& result_mux4051TwoInPin[2] < threshold 
&& result_mux4051TwoInPin[3] < threshold 
&& result_mux4051TwoInPin[4] < threshold 
&& result_mux4051TwoInPin[5] < threshold 
&& result_mux4051TwoInPin[6] < threshold 
&& result_mux4051TwoInPin[7] < threshold 
&& result_mux4051ThreeInPin[0] < threshold 
&& result_mux4051ThreeInPin[1] < threshold 
&& result_mux4051ThreeInPin[2] < threshold 
&& result_mux4051ThreeInPin[3] < threshold 
&& result_mux4051ThreeInPin[4] < threshold 
&& result_mux4051ThreeInPin[5] < threshold 
&& result_mux4051ThreeInPin[6] < threshold 
&& result_mux4051ThreeInPin[7] < threshold 
&& result_mux4051FourInPin[0] < threshold 
&& result_mux4051FourInPin[1] < threshold 
&& result_mux4051FourInPin[2] < threshold 
&& result_mux4051FourInPin[3] < threshold 
&& result_mux4051FourInPin[4] < threshold 
&& result_mux4051FourInPin[5] < threshold 
&& result_mux4051FourInPin[6] < threshold 
&& result_mux4051FourInPin[7] < threshold 
)
{
    someButtonsON = false;
  }

do you need this at the end, or is set elsewhere?

else {someButtonsON = true;}

Altho I was thinking the same as PaulS, check for a reading being >threshold, set someButtonOn = True, then skip the comparison like above.

I am not entirely sure I get it.. What I need is to check if ALL the inputs are below the threshold. It might be a language (natural language, I mean, English :)) issue, but the statement should be something like this:

if (even a single button is pressed){
someButtonsOn = true;
}

else if (none of the buttons is pressed){
someButtonsOn = false;
}

@PaulS: thank so much for the for loop idea. I tried that but it didn't work, so I thought it was wrong, but actually I am pretty sure I made some silly mistake.

But I am using now this code to check if someButtonsOn is true.

if(result_mux4051OneInPin[h]> threshold ||
result_mux4051TwoInPin[h]> threshold||
result_mux4051ThreeInPin[h]> threshold ||
result_mux4051FourInPin[h]> threshold){
    someButtonsON = true;
  }

I don't understand if this is enough to set someButtonsOn false when ALL of the buttons are below the threshold. Thank you so much everyone!

Okay, I think we're all in sync then. If a reading is greater than threshold, than someButtonON goes to true.

You can have an indexed loop like PaulS wrote, where all 32 comparisons are done. Or the less compactly written set of 32 comparisons I wrote, which allows you to add code that stops comparing once you find a reading that is > threshold. See 'goto' on the reference page: http://arduino.cc/en/Reference/Goto

someButtonsON = false;   // turn off the flag to start
 if (result_mux4051OneInPin[0] > threshold ){  // comparison #1
someButtonsON = true; // set the flag to show a button was pressed
goto end_of_comparisons;   // skip the remaining comparisons. 
}
 if (result_mux4051OneInPin[1] > threshold ){  // comparison #2
someButtonsON = true; // set the flag to show a button was pressed
goto end_of_comparisons;   // skip the remaining comparisons.
}

// etc. down to the last one:

 if (result_mux4051FourInPin[7] > threshold ){  // comparison #1
someButtonsON = true; // set the flag to show a button was pressed
goto end_of_comparisons;   // skip the remaining comparisons.
}

end_of_comparison:  // label,  goto's jump to here if a button press was found

If you add a break statement to the if block, the loop will end as soon as one of the 4 buttons tested in each iteration of the loop is pressed. At most, 3 more comparisons than minimally needed will be performed, but the goto is avoided, and the code looks cleaner, in my opinion.

[edit]Actually, the if test will stop as soon as it is conclusive that the result will be false, so break skips ALL extraneous tests.[/edit]

That's neat. I didn't know you could do that.

the if test will stop as soon as it is conclusive that the result will be false

This is called short circuit evaluation - http://en.wikipedia.org/wiki/Short-circuit_evaluation - and it has some nice uses to prevent error's.