I am putting together a simple simulated network in java, where i can add computers, servers, and connect two objects with ethernet ports. This is where the null pointer exception is being thrown, when i call "this.etherPort.addElement(t);"
import java.util.Vector;
public class Server extends Computer{
public Vector<Ethernet> etherPort;
public void addPort(Ethernet t)
{
this.etherPort.addElement(t);
}
}
This code is run when i make a new Ethernet object using this code:
public class Ethernet {
public Computer terminal1, terminal2;
public int volume;
public Ethernet(Computer term, Server term2)
{
this.terminal1 = term;
this.terminal2 = (Computer) term2;
if(term != null)
{
term.addPort(this);
}
if(term2 != null)
{
term2.addPort(this);
}
}
}