即使object的值为null,if(object_name == null)也会失败

时间:2016-04-24 02:33:39

标签: nullpointerexception null

航班flightToUpdate = null;                         //如果机场代码存在,则为变量赋值                         flightToUpdate = DatabaseOperations.getFlightByFlightNumber(columns [0]);

                    System.out.println(flightToUpdate);

                    if (flightToUpdate == null) {// If the location for the given airport code is not present, it needs to be added
                        Flight flightToAdd = new Flight();
                        flightToAdd.setFilghtNumber(columns[0]);
                        flightToAdd.setDepartureAirport(columns[1]);
                        flightToAdd.setDestinationAirport(columns[2]);
                        flightToAdd.setPrice(Double.parseDouble(columns[3]));
                        flightToAdd.setDatetime(df.parse(columns[4]));
                        flightToAdd.setPlane(columns[5]);
                        flightToAdd.setSeatsTaken(Integer.parseInt(columns[6]));

                        //Add to database
                        DatabaseOperations.AddFlight(flightToAdd);

                    } else { 
                        System.out.println("Success4");
                        DatabaseOperations.UpdateFlight(flightToUpdate);
                    }`enter code here`

0 个答案:

没有答案
相关问题