I just tested your code. Its working fine. no error I am getting output PC
public class StackOverFlow {
public static String[] CONSOLES = {
"PC",
"PS4",
"XBOX ONE",
"PS VITA"
};
public static void main(String arg[]){
System.out.println(getConsoleName(0));
}
public static String getConsoleName(int ID)
{
String rtext = "unknown";
try {
rtext = CONSOLES[ID];
} catch (Exception e) {
System.err.println(e);
}
return rtext;
}
}
If you are getting NullPointerException , please give complete code with main method to see where from it occurs.
0
solved NullPointerException When trying to get string element from array