저는 컴퓨터, 서버를 추가하고 이더넷 포트로 두 개의 객체를 연결할 수있는 간단한 시뮬레이션 네트워크를 자바에 넣고 있습니다. 이것은 "this.etherPort.addElement (t);를 호출 할 때 null 포인터 예외가 발생하는 곳입니다."자바에서 null 포인터 예외로 도움을 받으십시오.
import java.util.Vector;
public class Server extends Computer{
public Vector<Ethernet> etherPort;
public void addPort(Ethernet t)
{
this.etherPort.addElement(t);
}
}
이 코드를 사용하여 새로운 이더넷 개체를 만들 때이 코드가 실행 :
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); } } }
비공개 최종 목록이어야합니다. etherPorts = new ArrayList (); 결승전에서이 오류를 발견했을 것입니다. –