I need help on enclosing instance.

This is the part of code i am having trouble with:

SkillUse skilluse = new SkillUse();

SkillUse.SkillTimer skilltimer = new SkillUse.SkillTimer(skilluse, skillinstance, 67, j7);

This is the error:

an enclosing instance that contains SkillUse.SkillTimer is required.

Then I searched forum and changed to this form:

SkillUse skilluse = new SkillUse();

SkillUse.SkillTimer skilltimer = skilluse.new SkillUse.SkillTimer(skilluse, skillinstance, 67, j7);

Then I still gets error saying this:

'(' expected

SkillUse^.SkillTimer(skilluse, skillinstance, 67, j7);

I am lost at this point and I am novice at java.

Can anyone tell me how I can fix this problem?

Message was edited by:

yeo123

Message was edited by:

yeo123

[817 byte] By [yeo123a] at [2007-11-26 21:57:43]
# 1

The smartest thing to do would be to add a factory method in the outer class:

public class SkillUse {

public class Timer {

private Timer(String etc){}

}

public Timer newTimer(String etc) {

return new Timer(etc);

}

public static void main(String[] args) {

//demo:

SkillUse use = new SkillUse();

SkillUse.Timer timer = use.newTimer("etc...");

}

}

Also, in the code you gave, do you *really* want to pass the outer instance

to the inner constructor? That is redundant.

DrLaszloJamfa at 2007-7-10 3:55:09 > top of Java-index,Java Essentials,Java Programming...