I'm not sure if I am doing this right, but I keep getting an error saying my array "currentRoute" cannot be resolved into a variable. I'm assuming this is because I have declared the array in a different scope. Is there any way I can get this to work while still declaring the variable in within my switch statement and while still using a simple array? (I cannot use an arraylist, as the rest of my code would be affected)
switch (routeID)
{
case "1" : {
String[] currentRoute = new String[Route1.length];
currentRoute = Route1;
}
case "96" : {
String[] currentRoute = new String[Route96.length];
currentRoute = Route96;
}
}
// print out values in currentRoute
for (int i = 0; i < currentRoute.length; i++)
{
System.out.println(currentRoute[i]);
}
there are a lot more switch statements, but I have just included 2 for this example.
EDIT:both switch and for statements are located within the same method.