tags:

views:

149

answers:

3
+2  A: 

etherPort is null. You are apparently never initializing it with an actual Vector. I think you want:

public class Server extends Computer{

     public Vector<Ethernet> etherPort; 

     public Server()
     {
        etherPort = new Vector<Ethernet>();
     }

     public void addPort(Ethernet t)
     {
        this.etherPort.addElement(t);
     }
}
Matthew Flaschen
+3  A: 

You didn't initialize the vector. Should be:

public Vector<Ethernet> etherPort = new vector<Ethernet>();
Itay
Should probably be private final List<Ethernet> etherPorts = new ArrayList<Ethernet>(); The final would have caught the error.
Tom Hawtin - tackline
+9  A: 

You need to instanciate your etherPort member :

public class Server extends Computer{

     public Vector<Ethernet> etherPort = new Vector<Ethernet>(); 

     public void addPort(Ethernet t)
     {
        this.etherPort.addElement(t);
     }
}

You should make sure that addPort() is not overriding a method called from your Computer constructor, though. Given the context, I assume it's safe (i.e. Computer has no addPort() method).

As stated below in a comment, it's generally better to use interfaces that don't constrain the containers implementations : you'd better declare etherPort as a

List<Ethernet>

instead of a

Vector<Ethernet>

and use etherPort.add(element) instead of the Vector-specific addElement method.

subtenante