Java array error

I did a script to make an ‘acknowledge all’ button:

p = 0 while p < 22: table = event.source.parent.getComponent("Alert Summary") alerts = table.alerts alertSys = alerts.getValueAt(p,"System") alertPath = alerts.getValueAt(p,"Path") alertState = alerts.getValueAt(p,"State Name") system.alert.acknowledgeAlert(alertSys,alertPath,alertState) p += 1

it runs perfectly except for this error:

[code] Traceback (innermost last):

File “event:actionPerformed”, line 5, in ?

java.lang.ArrayIndexOutOfBoundsException: 0

java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 0
[/code]

How can I solve this?

Hi Sam. Welcome to the forums!

I have to say that you confused me. Don’t worry about that, because my wife says it’s not hard to do! :laughing:

But doesn’t the Alert summary table already have an Acknowledge All button?

EDIT: In the meantime, try this:

table = event.source.parent.getComponent("Alert Summary")
alerts = table.alerts

for row in alerts: 
   alertSys = alerts.getValueAt("System")
   alertPath = alerts.getValueAt("Path")
   alertState = alerts.getValueAt("State Name")
   system.alert.acknowledgeAlert(alertSys,alertPath,alertState)

I think what is happening is that your script assumes that there is always 22 rows in the dataset. This may or may not be true, depending on how you have the component set up. Using the for row method should work, regardless of the number of rows in the dataset.

Also, ‘table’ is getting re-initialized on every iteration of the loop. I don’t know if that was intentional or not, but most times you should be able to set it just once.

Thanks!

Your wife was right, it was not so hard. The problem was about the array’s range. I will try using alerts dataset properties. However, the script was incorrect.