1

I have this public abstract class MyClass with abstract method abstract public void myMethod() in my Android library project.

I am trying to build a concrete implementation of this class in another project, which is an application project and references the library project. The method implementation in the subclass is marked with "@Override" and Eclipse gives me the following error:

The method myMethod() of type MySubClass must override or implement a supertype method

I remove "@Override" and error becomes a warning:

The method MySubClass.myMethod() does not override the inherited method from MyClass since it is private to a different package

What does this mean? Yes, these classes are in different projects and different packages but what does this have to do with inheritance? Both methods are public.

Here is the code for the superclass:

package com.emret.myPackage;

//Some imports here

public abstract class ThingsProvider {

//Class code here

    abstract public void createThings();

}

Here is the subclass:

package com.emret.myPackage.subPackage;

//Some imports here

public class SmallThingsProvider extends ThingsProvider {

//Class code here

    @Override
    public void createThings() {
        createThing(0, R.drawable.cat, R.raw.cat);
        createThing(1, R.drawable.dog, R.raw.dog);
        createThing(2, R.drawable.cow, R.raw.cow);
        createThing(3, R.drawable.sheep, R.raw.goat);
        createThing(4, R.drawable.bicycle, R.raw.bicycle);
    }
}
4

2 回答 2

3

似乎“yshavits”指出了确切的痛点,但其他限制阻碍了。

我的抽象方法一开始是包私有的。我在子类中遇到错误时将其更改为public,但将其更改为public后错误并没有消失。

事实证明,只要引用的项目被完整且成功地编译,引用项目中的引用就不会更新。引用项目中的任何单个错误都会阻止成功编译,并阻止引用项目检测其更新的类信息。

我引用的项目有另一个错误。即使与上面的类完全分开,它也会阻止成功编译并阻止引用项目中的引用更新。

后台编译器并不像我希望的那样聪明。

于 2012-12-17T15:33:54.557 回答
0

我认为您使用的是 Java 1.5,请转到项目/属性,Java 编译器并确保您至少使用 Java 1.6。

于 2012-12-17T15:28:15.407 回答