What I want to do is initialize an array of strings and then fill each space with a different string, like so:
int year = 1995; //the current year i'm working with
String[] Year; //Initialize the year string
String j;
for(int i=(year-50); i < year; i++)
{
j = Integer.toString(i); //Converts the integer to a string
Year[i] = j; //EXCEPTION OCCURS HERE WHEN I SET 'String[] Year'
//equal to 'null'
}
The problem is that I can't initialize the string because I get the following error: 'The local variable Year may not have been initialized'
If I set String[] Year = null
, then I can initialize the string. HOWEVER, if I do that, an exception is thrown when attempting to run & compile the code: java.lang.NullPointerException
I know that my code could be shorter, but I am trying to isolate the problem...