When I tried to call a class called “ShowHistory” in Java, an error shows: “The type ShowHistory must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)”
Here is my code:
public class ShowHistory extends JFrame implements ActionListener {
...
}
The IDE recommended me to make this class to be an abstract class, but when I convert it to be abstract, another piece of code goes wrong:
ShowHistory frame = new ShowHistory();
It shows: “Cannot instantiate the type ShowHistory”.
Is there any idea to solve this problem?
What this means is that for your class
ShowHistoryto implementActionListener, it must implement all of the methods defined by the interface. In this case, that is the methodactionPerformed(ActionEvent).When you changed
ShowHistorytoabstract, you made it so that ShowHistory can’t be instantiated, and it’s child classes (who may be instantiated, if not abstract) will be responsible for defining the methods inActionListener.