Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Constructor inheritance(????) problem 1

Status
Not open for further replies.

alwaysAnewbie

Programmer
Sep 12, 2002
23
0
0
US
I have constructor Player and constructor Owner in their respective classes. In constructor Owner I have a method (addRosterPlayer)i need to pass an instance of constructor Player. I have imported the entire package into both but class Owner will not compile. The error is "cannot resolve symbol" on method addRosterPlayer(Player p). Any idea what I'm missing here? (Yes I have RTFM'ed I'm just not getting it)

Class Player code
Code:
package  draft;

import draft.*;

public class Player {
        String f_name;
        String l_name;
        String pro_team;
        String position;
        int player_id;

        public Player(String fn, String ln, String team, String pos, int id) {
                l_name = ln;
                f_name = fn;
                pro_team = team;
                position = pos;
                player_id = id;
        }

        public void addDraftListPlayer(Player p) {

        }

}

Class Owner code
Code:
package  draft;

import draft.*;

public class Owner {
        String f_name;
        String l_name;
        int team_id;
        int league_id;
        String team_name;

        public Owner(String fn, String ln, int team, String tn, int league) {
                l_name = ln;
                f_name = fn;
                team_name = tn;
                team_id = team;
                league_id = league;
        }

        public String getTeamName() {
                return this.team_name;
        }

        public void addRosterPlayer(Player p) {

        }

}

Thanks for your help.
 
You don't need to import a package in a class that is in the same package as itself.

I expect your problem is you need to set your CLASSPATH correctly.

--------------------------------------------------
Free Database Connection Pooling Software
 
I think problem is there in your envt setting, i executed ur code on machine without any issues
 
Thanks for the replies. Hopefullly this will relieve some of the soreness in my head (from banging it on the wall).

I only did the import when the problems first occured. I checked my classpath and the first entry is a period(current directory). That should handle the classpath issue. Any other thoughts on the environment side?
 
The only "environemnt" issue will be your CLASSPATH.

--------------------------------------------------
Free Database Connection Pooling Software
 
Ok. To test my classpath I compiled a known working source file in a directory on a different disk. It compiled successfully. Doesn't that indicate that the classpath is ok?
 
Well it depends on the code you are compiling.

Imagine that you Owner.java and Player.java are in the following directory :

/home/test/java/draft

Then you would need to export your CLASSPATH to this directory :

/home/test/java/


--------------------------------------------------
Free Database Connection Pooling Software
 
That was it. I had to explicitly set my classpath to get it to work. I now have a much greater understanding of what the classpath does. Thanks again for everyones help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top