I’m trying to create an object and add it to an array I created as a parameter GUI object I constructed. For some reason I keep getting TheDates cannot be resolved to a Variable.
Object being constructed:
public static void main(String[] args)
{
DateDriver myDateFrame = new DateDriver();
}
//Constructor
public DateDriver()
{
outputFrame = new JFrame();
outputFrame.setSize(600, 500);
outputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String command;
Date [] theDates = new Date[100]; //this is the array I am having issues with
int month, day, year;
...
}
This is where my problem with theDates is:
public void actionPerformed(ActionEvent e)
{ //The meat and Potatoes
if ( e.getSource() == arg3Ctor)
{
JOptionPane.showMessageDialog(null, "3 arg Constructor got it");
int month = Integer.parseInt(monthField.getText());
int day = Integer.parseInt(dayField.getText());
int year = Integer.parseInt(yearField.getText());
theDates[getIndex()] = new Date(month, day, year);//here is the actual issue
}
}
I don’t know if I’m over thinking it or what, I’ve tried making the array static, public, etc. I’ve also tried implementing it as myDayeFrame.theDates.
Any guidance is greatly appreciated
You likely have a scope issue. theDates was declared in the constructor and is visible only in the constructor. A possible solution: declare it as a class field. Sure initialize it in the constructor, but if it is declared in the class, it is visible in the class.