Target Exception Error from Solenoid Array

Hello, I have recently been looking into making my solenoids operate
based off an Array. I get no build Errors or warnings. However when i
run it i get a Target Exception Error.
VxWorks6x_10.4.86: Exception in Kernal Task FRC_RobotTask:0x1e37368
at pc=0x1DE93B0 in RobotDemo::OperationControl()
at (Address of main.cpp)

Vector 0x300 : Data Access addr=0xEEEEEEE status=0xDC1630

The Code that matters

bool states [4] = {false,false,false,false}
bool prestates [4] = {false,false,false,false}
bool inoutbut [4] = {false,false,false,false}

class RobotDemo : public SimpleRobot
{
Solenoid* solenoids[5];
}
// more stuff inbetween

void OperatorControl(void)
{
solenoids[1] = new Solenoid(1);
solenoids[2] = new Solenoid(2);

while (IsOperatorControl)
{
for(int b=1; b<5; b++)
{
inoutbut** = stick.GetRawButton(b) // the stick is correctly defined

      if(inoutbut** == true)
     {
         g=b;
          states[g]= !prestates[g];
          solenoid [g]-&gt;Set(states[g]) // the debugger shows this as wrong
          prestates[g] = !prestates [g];
      }
    }
}****

One obvious problem is that you only create 2 solenoid objects, but call set on 4 of them.

I see a few problems:

-You lack a semicolon on the line that is bad; C generally prefers semicolons (although I suspect you did not copy-paste the code, but rather re-typed it)

-You are assigning 4 buttons to toggle the state of 4 pistons when pressed (yes?), however, it appears as though the If will run every cycle that the button is pressed (constantly inverting/setting the piston while the button is held), you would need a check to see if the button is pressed but wasn’t last iteration.

-Is there any need for states and prestates? Couldn’t you just say

state** = !state**; solenoid**->set(state**);

and get the same result?

-What are you doing where you need an array of solenoids? In embedded programming such as FRC robots, I’ve always hated working with arrays of objects, as most objects we use have a specific purpose and are handled in different ways (depending on the subsystem they operate under, for example), and usually robots are simple enough where having a few references isn’t a bad or messy thing.********

Thanks for the feed back. As for semi-colons yes i retyped it not copy and paste. I will try to declare the rest of the array and see if that works. The only reson i am attempting to do this is as a test of concept not because it is an essential part of the code.

Your indexing into the array is 1 to 4, rather than 0 to 3

I figuered it out thanks for all the help. It was the indexing (0-3) and the incomplete slots in the array