java - Im getting null pointer exception in my object array -
Therefore, I am creating an array of seats on an airplane, the property seat number , seat type , and traveler . First of all .. make my code seat object in a different class: I have in my main class: I found that many people did not have the problem of creating arrays with non-null objects, but when I try to block the code which I think, Still a null pointer exception What am I missing this object is not empty? Your main () method is reaching the static seat list field, which is not populated (Seitlist () Has not been called yet). Seatlists should probably be made non-static, and to be transported through a clogging method, the object starts completely before applying it. Make a / p> or sitelist () to call it and call it with a static initiator to call it.
public class seat {Private enter seat number; Private string passenger; Private string seat type; Public seat (int seat number, string seat type, string passenger) {ctnm = this; with number; SeatType = this.seatType; Passenger = this.passenger; } Public int receive () {return seat number; } Public string received passenger () {return travelers; } Public string getSeatType () {return seatType; }
import javax.swing. *; Import java.awt. *; Import java.awt.List; Import java.util. *; Public Class Airplane Reservation {public stationary seat} Seat list = new seat [12]; Public Zero Seats List (for (Int i = 0; I & lt; Ceelist.Langt; I ++) {Seatlist [I] = New seat (I, blank, blank);} Seat seat 1 = New seat (1, "First Class", "Collins"); seatList [0] = seat1; Seat seat 2 = New seat (2, "First class", "blank"); seatList [1] = seat2; Seat seat 3 = New seat (3, "First class", "Fewre"); seatList [2] = seat3; Seat seat 4 = New seat (4, "First class", "Kinnard"); seatList [3] = seat4 ;; Seat Seat 5 = new seat (5, "coach", "blank"); seatList [4] = seat5; seat seat 6 = new seat (6, "coach", "blank"); seatList [5] = sea Seat seat 7 = new seat (7, "coach", "morgans"); seatList [6] = seat7; seat seat 8 = new seat (8, "coach", "rohan"); seatList [7] = Seat8; seat seat 9 = new seat (9, "coach", "shatarov"); seatList [8] = seat9; seat seat 10 = new seat (10, "coach", "sword"); seatList [9] = Seat10; seat seat 11 = new seat (11, "coach", "blank"); seatList [10] = seat11; seat seat 12 = new seat (12, "coach", "tickness"); seatList [11] = Seat12;} Public static zero main (string [] args) {System.out.println ("seat \ tPassenger"); Println (seatList [0] .getSeatNumber ());
Exception in thread "main" java.lang.NullPointerException on airplane. Reservation.main (Airplane Seva.Java45)
Comments
Post a Comment