Java操作侦听器不使用数组
这个代码有什么问题?当我点击按钮时,我试图让它转到下一个名为bk的排序数组Java操作侦听器不使用数组,java,swing,actionlistener,Java,Swing,Actionlistener,这个代码有什么问题?当我点击按钮时,我试图让它转到下一个名为bk的排序数组 Book[] bk = new Book[5]; bk = sortArray(bk); final JTextArea textArea = new JTextArea(); JButton btnNext = new JButton("Next"); btnNext.addActionListener(new ActionListener() { public void actionPerformed(Ac
Book[] bk = new Book[5];
bk = sortArray(bk);
final JTextArea textArea = new JTextArea();
JButton btnNext = new JButton("Next");
btnNext.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for (int i = 0; i < bk.length; i++)
textArea.append("\n" + bk[i+1]);
}});
不包括最后宣言:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The final local variable bk cannot be assigned. It must be blank and not using a compound assignment
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
Cannot refer to a non-final variable bk inside an inner class defined in a different method
Cannot refer to a non-final variable bk inside an inner class defined in a different method
如何解决此问题?请尝试以下操作:
Book[] bk = new Book[5];
// fill bk here
final Book[] bkSorted = sortArray(bk);
试试这个:
Book[] bk = new Book[5];
// fill bk here
final Book[] bkSorted = sortArray(bk);
试试这个:
Book[] bk = new Book[5];
// fill bk here
final Book[] bkSorted = sortArray(bk);
试试这个:
Book[] bk = new Book[5];
// fill bk here
final Book[] bkSorted = sortArray(bk);