Cannot refer to non variable inside Action listener (Jframe)

前端 未结 1 1192
失恋的感觉
失恋的感觉 2021-01-25 22:16

The following program\'s goal is to ask the user to input a resistor value, then of which the program will output the corresponding colors for each digit. This thus not include

1条回答
  •  [愿得一人]
    2021-01-25 23:04

    In Java you cannot refer to not final variables inside anonymous inner class. You attempt to access array3 inside anonymous implementation of ActionListener. You can simply change array3 to final, ie:

    final String [] array3 = new String [3];
    

    Also, to print a content of array you can use Arrays.toString():

    JOptionPane.showMessageDialog(null, "The Colors are : " + (Arrays.toString(array3)));
    

    0 讨论(0)
提交回复
热议问题