I have a LWUIT class which has a List
, the list itself contains a Label as an item.
My idea simply to make an action for the list when I focus on the label.
I get the following error, when compiling the class:
anonymous Midlet$2 is not abstract and does not override abstract method focusLost(com.sun.lwuit.Component) in com.sun.lwuit.events.FocusListener
String s = ("Focus me");
final com.sun.lwuit.Form f = new com.sun.lwuit.Form();
final com.sun.lwuit.List D = new com.sun.lwuit.List();
final com.sun.lwuit.Label l = new com.sun.lwuit.Label(s);
D.addItem(l);
f.addComponent(D);
D.addFocusListener(new com.sun.lwuit.events.FocusListener () {
public void focusGained(com.sun.lwuit.Label l)
{
}
public void focusLost(com.sun.lwuit.Label l)
{
}
});
All details of what is wrong with your code are in the error message, you just need to carefully read it. Look,
word anonymous
and sign $
in Midlet$2
tell you something is wrong in the anonymous class.
In your code snippet, there's only one such class: new com.sun.lwuit.events.FocusListener
does not override abstract method focusLost(com.sun.lwuit.Component)
means your anonymous class misses a definition of a method with such a signature (signature is method name and type of parameters)
Look closer in the methods you defined in that anonymous class, is there a method compiler is complaining about?
At the first glance, you may think it's there, there's a method called focusLost
- but (!) you need to remember that signature is not only method name, but also parameters type - and (!) if you look closer, you'll find out that parameter type is not that is said to be required in error message.
Your anonymous class has method focusLost(com.sun.lwuit.Label)
but error message says there should be method with different signature (different parameter type) - focusLost(com.sun.lwuit.Component)
.
To fix this compilation error, add to the anonymous class new com.sun.lwuit.events.FocusListener
a method with required signature: focusLost(com.sun.lwuit.Component)
.