我的结构类似于:
class OuterClass{
AnimatorListener sth;
public OuterClass(){
sth = new InnerClass();
}
public class InnerClass implements AnimatorListener{
public InnerClass(){}
public void doSomething(){}
//assuming animator listener methods implemented
}
public void tryingToDoSomething(){
sth.doSomething(); //I cannot use this, simply it is not seen by eclipse.
}
}
为什么我doSomething()
时无法调用sth
对象的tryingToDoSomething()
方法?
答案 0 :(得分:1)
更改构造函数语法。这是错误的
public OuterClass{
sth = new InnerClass();
}
将此更改为
public OuterClass(){
sth = new InnerClass();
}
答案 1 :(得分:1)
您的对象sth
属于班级AnimatorListener
,但它应属于InnerClass
。希望这有帮助,快乐编码。