0

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!!

3
  • Kindly paste the exception so that details can be viewed. And do post your model class customer. Commented Feb 24, 2014 at 3:34
  • Do you know what NUllPointerException means. If you do, just look at the line its pointing do and figure out why that line is producing a null Commented Feb 24, 2014 at 3:39
  • Try putting your initComponents before the other three lines. Commented Feb 24, 2014 at 3:41

1 Answer 1

1

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());


    }
Sign up to request clarification or add additional context in comments.

1 Comment

damn it... im sure its too late to code here in UK :D you are 100% right! thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.