I get an error trying to implement an OnTo开发者_运维知识库uchListener:
The method onTouch(View, MotionEvent) of type new View.OnTouchListener(){} must override a superclass method
I have no idea why it's not working as it seems I'm overrriding the method correctly:
public class MyActivity extends Activity
{
...creation code etc...
OnTouchListener mTouchListener = new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
...touch code...
}
}
}
Any ideas on how I can debug this?
In Eclipse, go to Windows>Preference>Java>Compiler and select 1.6.
You might be using 1.5, and 1.5 does not allow @Override on interfaces methods, but just on superclass method. 1.6 does.
If it still doesn't work, remove the @Override line...
public class MyActivity extends Activity
{
...creation code etc...
OnTouchListener mTouchListener = new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
...touch code...
}
}
}
View.OnTouchListener mTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
};
that compiles just fine, are you sure that there are no syntax errors ? What are you compiler settings ? java 5 or 6 ?
精彩评论