开发者

Eclipse can't generate getters and setters in a special case; Need help tracking the problem down

After I create classes in a certain package, and add an enum declaration inside the class, I can no longer generate getters and setters. I suspect it has something to do with the project settings or setup, but I'm not sure where to look. If I make the same class in its own project, I don't see the problem.

public class ExampleClass {

    private enum SampleEnum {
        A开发者_如何学运维, B, C;
    }

    private SampleEnum e;

    private String variableToGenerateCodeOn;

}

When I try to generate getters and setters for variableToGenerateCodeOn, I get this error: cannot analyze selected field 'variableToGenerateCodeOn'

Edit When I resolved the errors with tomcat, the problem didn't go away. Of two others on my team, one was able to repro the bug with the same code, the other wasn't. I am now guessing it has to do with some workspace settings, but I am open to additional ideas. The original thought is still preserved below:

Outdated/Ruled-out idea I have several errors from some included tomcat files. One of them that might be applicable:

Description: Enumeration cannot be resolved to a type
On Detail: sessionDetail.jsp
In Folder: {myproject}/tomcat/webapps/manager/WEB-INF/jsp
Location: line 104


This is a defect in Eclipse Indigo. The presence of some nested declaration confuses the getter/setter code. You can report it in bugzilla. For now, move the enum out to its own file or type the getters and setters by paw. [dog joke]


Eclipse behaves quite strange and nondeterministically when there are errors - even if they are in a different file and seem totally unrelated. So try to remove those errors, then Eclipse will probably be able to generate the setters and getters (your example works for me).


I got this error for the eNums keyword as I used the class name 'practice'. Eclipse has a errorshot when you declare the class,method or variables starting with pract,ract,ria.

You can try to remove word variable ('variableToGenerateCodeOn')in your variable declaration, trying some other word could help you,

or check anywhere else in your code rhyming any declaration as shown above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜