I'm having trouble with a java application. When I try and run the program it shows a java.lang.NullP ointerException in the "tic.getClient( ).getClientTick etList().add(ti c);" line (it's in bold). I know it has something to do with an object being null, but I just can't figure out which... Can anyone help? Any suggestions are greatly appreciated :) (By the way, I translated the code to english but I might have forgotten to translate a word, so if there's something that doesn't make sense please tell me so I can fix it. Oh and I didn't include the Ticket class code because it's a lot, but if it's necessary I'll post it)
rentACar Class(only the method that's not working)
Code:
public void makeTicket(){ String clientNum=JOptionPane.showInputDialog("Client's number"); if (foundClient(clientNum)){ findState(); if (availableCars.size()!=0){ Transportation vehic=(Transportation)JOptionPane.showInputDialog(null,"Choose vehicle","Vehicles",JOptionPane.PLAIN_MESSAGE,null,availableCars.toArray(), 0); int days=0; do{ try { days=Integer.parseInt(JOptionPane.showInputDialog("Number of days")); if (days<1){ JOptionPane.showMessageDialog(null,"ERROR"); } } catch(NumberFormatException nFE){ JOptionPane.showMessageDialog(null,"ERROR"); } } while (days<1); Ticket tic=new Ticket(); tic.setDays(days); tic.setDateTaken(Calendar.getInstance()); tic.getFinalDate().add(Calendar.DATE, days); tic.setState("Not Cancelled"); tic.setVehicle(vehic); tic.setNum(ticketList.size()-1); if (vehic instanceof notBike){ if (((notBike)tic.getVehicle()).getType().equals("Car")){ tic.setAmount(days*125); }else{ if (((notBike)tic.getVehicle()).getType().equals("Bus")){ tic.setAmount(days*200); }else{ if (((notBike)tic.getVehicle()).getType().equals("Motorcycle")){ tic.setAmount(days*80); }else{ tic.setAmount(days*60); } } } }else{ tic.setAmount(days*30); } for (int i=0; i<clientList.size();i++){ if (((Client)clientList.get(i)).getClientNum().equalsIgnoreCase(clientNum)){ tic.setClient((Client)clientList.get(i)); [B] tic.getClient().getClientTicketList().add(tic);[/B] ticketList.add(tic); i=clientList.size(); } } }else{ JOptionPane.showMessageDialog(null,"There are no vehicles available"); } }else{ JOptionPane.showMessageDialog(null,"The client does not exist"); } }
Client Class
Code:
package project; import java.util.ArrayList; public abstract class Client { protected String clientNum; protected String name; protected String tel; protected String address; protected ArrayList clientTicketList=new ArrayList(); public Client() { } public Client(String clientNum, String name, String tel, String address, ArrayList clientTicketList) { this.clientNum = clientNum; this.name = name; this.tel = tel; this.address = address; this.clientTicketList = clientTicketList; } public String getClientNum() { return clientNum; } public void setClientNum(String clientNum) { this.clientNum = clientNum; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public ArrayList getClientTicketList() { return clientTicketList; } public void setClientTicketList(ArrayList clientTicketList) { this.clientTicketList = clientTicketList; } public String displayInfo(){ return "Name: "+name+"\nClient Number: "+clientNum+"\nPhone Number: "+tel; } public String toString(){ return Name: "+name+"\nClient Number: "+clientNum+"\nPhone Number: "+tel+"\nAddress: "+address; } }
Comment