What is wrong with this code? I am trying to have it go to the next sorted array named bk when I click on the button.
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]);
}});
But if I declare it as final the line that sorts it tells me to take the final declaration out.
Here the error with the final declaration:
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
And w/o the final declaration:
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
What can I do to fix this problem?