1

In this when it comes to for loop and "id" it's shows null point exception. i commented all intgers and then code works fine.can anyone say what's the wrong of my code...

 public List<HotelRoom> getallstudent() {
            String sql = "SELECT * FROM hotelroom";

            List<HotelRoom> list = new ArrayList<HotelRoom>();

            List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql);

            int id = 0;
            int numBed = 0;
            long prce = 0;
            int size = 0;

            for (Map row : rows) {
                HotelRoom hm = new HotelRoom();

                 id = Integer.parseInt(row.get("id").toString());
                 numBed = Integer.parseInt(row.get("numberOfBeds").toString());
                 prce = Long.parseLong(row.get("price").toString());
                 size = Integer.parseInt(row.get("size").toString());

                hm.setId(id);
                hm.setGuestHouseName(row.get("guestHouseName").toString());
                hm.setImageLocation(row.get("imageLocation").toString());
                hm.setLocation(row.get("location").toString());
                hm.setNumberOfBeds(numBed);
                hm.setPrice(prce);
                hm.setRoomType(row.get("roomType").toString());
                hm.setSize(size);

                list.add(hm);
            }
            return list;

        }

0 Answers0