JAVA עף בזמן ריצה- דחוף!
שלום,
החלק הזה עף לי בזמן ריצה מסיבה לא ברורה..
אני יודע שזה קשור למערך, אבל המערך בגודל 2 (כלומר:0,1)
private Airfield[] a= new Airfield[2];
.....
public void DepartAndLand (int num_of_flight) throws InterruptedException
{
x= rand.nextInt(2);
System.out.println("num "+num_of_flight);
System.out.println("x "+x);
f= new Flight(a, x, num_of_flight, 0, 1);
}
ואז עוברים לקלאס השני:
.....
public Flight(Airfield[] m_a, int m_flight_direction, int m_num_of_flight, int m_num_of_airfield_for_depart, int m_num_of_airfield_for_land) throws InterruptedException
{
// super(null); // what to put here?
a=m_a;
setFlightDirection (m_flight_direction);
setNumOfFlight(m_num_of_flight);
setnumOfAirfieldForLand(m_num_of_airfield_for_land);
setnumOfAirfieldForDepart(m_num_of_airfield_for_depart);
}
.......
public synchronized void depart () throws InterruptedException
{
int x= (int)((Math.random()*5)+2);
try{
num_of_airlinerote_for_depart=a[num_of_airfield_for_depart].depart(num_of_flight);
}
השורה שעצרתי (a[num...] זה מראה שגיאה:
Exception in thread "Thread-3" java.lang.NullPointerException
at Flight.depart(Flight.java:60)
at Flight.run(Flight.java:28)
אין לי מושג מה מצביע פה ל-NULL....
שלום,
החלק הזה עף לי בזמן ריצה מסיבה לא ברורה..
אני יודע שזה קשור למערך, אבל המערך בגודל 2 (כלומר:0,1)
private Airfield[] a= new Airfield[2];
.....
public void DepartAndLand (int num_of_flight) throws InterruptedException
{
x= rand.nextInt(2);
System.out.println("num "+num_of_flight);
System.out.println("x "+x);
f= new Flight(a, x, num_of_flight, 0, 1);
}
ואז עוברים לקלאס השני:
.....
public Flight(Airfield[] m_a, int m_flight_direction, int m_num_of_flight, int m_num_of_airfield_for_depart, int m_num_of_airfield_for_land) throws InterruptedException
{
// super(null); // what to put here?
a=m_a;
setFlightDirection (m_flight_direction);
setNumOfFlight(m_num_of_flight);
setnumOfAirfieldForLand(m_num_of_airfield_for_land);
setnumOfAirfieldForDepart(m_num_of_airfield_for_depart);
}
.......
public synchronized void depart () throws InterruptedException
{
int x= (int)((Math.random()*5)+2);
try{
num_of_airlinerote_for_depart=a[num_of_airfield_for_depart].depart(num_of_flight);
}
השורה שעצרתי (a[num...] זה מראה שגיאה:
Exception in thread "Thread-3" java.lang.NullPointerException
at Flight.depart(Flight.java:60)
at Flight.run(Flight.java:28)
אין לי מושג מה מצביע פה ל-NULL....