user3266312
user3266312

Reputation: 43

Throws Exception in netbeans when using GET

I'm trying to retrieve data from my Model class into textfield via GET, although nullpointexception is throwing an error

The code in the View class is =

  public View_EditCustomer(Model_Customer cust) {
        customer = cust;
        txtname.setText(customer.GetFName());
        txtSecondName.setText(customer.GetLName());

        initComponents();
    }

and in another View class it is =

private void btnSelectActionPerformed(java.awt.event.ActionEvent evt) {                                          
      ListSelectionModel rowSM = jTable1.getSelectionModel();
            int row = rowSM.getMinSelectionIndex();
            int Appointment_ID = (Integer)resultModel.getValueAt(row, 0);
            Model_Customer cust = null;
            try{
                cust = Controller_ManageCustomer.GetCustomer(Appointment_ID);
                new View_EditCustomer(cust).setVisible(true); 
            }catch(Exception ex){
                JOptionPane.showMessageDialog(this,ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
            }
    }          

Model_Customer code parts =

  public static Model_Customer QueryID(int Appointment_ID) throws Exception
    {
        try{
            Statement stmt = Model_Customer.conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM appointment WHERE appointmentid="+Appointment_ID+" LIMIT 1;");
            if(rs.next())
                return new  Model_Customer(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12));
        }catch(Exception e){
            throw new Exception(e.getMessage());
        }
        return null;
}


private Model_Customer(int Appointment_ID, String FName, String LName, String Registration, String Make, String Model, String Engine, String Year, String Mileage, String Type, String Date, String Time)
    {
        this._Appointment_ID=Appointment_ID;
        this._Type=Type;
        this._Time=Time;
        this._Date=Date;
        this._FName=FName;
        this._LName=LName;
        this._Make=Make;
        this._Model=Model;
        this._Engine=Engine;
        this._Year=Year;
        this._Mileage=Mileage;
        this._Registration=Registration;
        this._inSync=true;    
    }
    public int GetID()
    {
        return this._Appointment_ID;
    }
    public String GetFName()
    {
        return _FName;
    }
    public String GetLName()
    {
        return _LName;
    }
    public String GetRegistration()
    {
        return _Registration;
    }

    public String GetMake()
    {
        return _Make;

    }
    public String GetModel()
    {
        return _Model;
    }


    public String GetEngine()
    {
        return _Engine;
    }
    public String GetYear()
    {
        return _Year;
    }
    public String GetMileage()
    {
        return _Mileage;
    }
    public String GetType()
    {
        return _Type;
    }
    public String GetDate()
    {
        return _Date;
    }
    public String GetTime()
    {
        return _Time;
    }

In debugging Model_Customer cust is actually populated by data and it actually goes to the end to txtname.setText(customer.GetFName()); goes to Model_Customer GetFName and should retrieve the name but throws an exception (int)0. Would really appreciate your help!!

Upvotes: 0

Views: 253

Answers (1)

alkber
alkber

Reputation: 1436

Shouldn't initComponents(); be called before using TextViews ?

public View_EditCustomer(Model_Customer cust) {

        initComponents();
        customer = cust;
        txtname.setText(customer.GetFName());
        txtSecondName.setText(customer.GetLName());


    }

Upvotes: 1

Related Questions