Help me pls. I have some problems with method getClient(), bring only two classes.

package drugstore;

public class DrugstoreFrame extends JFrame {
    Client person;
    ...

    public Client getClient(){
         person.setAccount(getField(jTextField4));
         person.setPassword(getField(jPasswordField2));
         person.setFio(getField(jTextField5));
         person.setAddress(getField(jTextField6));
         person.setTelephone(getField(jTextField3));
         person.setAdditionalInformation(getField(jTextField7));
         return person;
    }
    private String getField(JTextField field){
        return field.getText();
    }
    public void jButton10_mouseClicked(MouseEvent e) {
       person = getClient();
       try{
           database.newPerson(person);
      }catch(DataAccessException exception){
        }
 }
}
package drugstore;

public class Client {
    private String fio = ""; 
    private String address = ""; 
    private String telephone = ""; 
    private String additional_information = ""; 
    private String account = ""; 
    private String password = ""; 
    private int client_id; 

 Client(int client_id){
     this.client_id = client_id;

 }

    public void setClientId(int client_id){
        this.client_id = client_id;
    }
    public void setFio(String fio){
        this.fio = fio;
    }
    public void setAddress(String address){
        this.address = address;
    }
    public void setTelephone(String telephone){
        this.telephone = telephone;
    }
    public void setAdditionalInformation(String additional_information){
        this.additional_information = additional_information;
    }
    public void setAccount(String account){
        this.account = account;
    }
    public void setPassword(String password){
        this.password = password;
    }
}

When performing the program we receive necessary error.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at drugstore.DrugstoreFrame.getClient(DrugstoreFrame.java:293)
	at drugstore.DrugstoreFrame.jButton10_mouseClicked(DrugstoreFrame.java:389)
	at drugstore.DrugstoreFrame_jButton10_mouseAdapter.mouseClicked(DrugstoreFrame.java:409)
	at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
	at java.awt.Component.processMouseEvent(Component.java:5491)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
	at java.awt.Component.processEvent(Component.java:5253)
	at java.awt.Container.processEvent(Container.java:1966)
	at java.awt.Component.dispatchEventImpl(Component.java:3955)
	at java.awt.Container.dispatchEventImpl(Container.java:2024)
	at java.awt.Component.dispatchEvent(Component.java:3803)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
	at java.awt.Container.dispatchEventImpl(Container.java:2010)
	at java.awt.Window.dispatchEventImpl(Window.java:1774)
	at java.awt.Component.dispatchEvent(Component.java:3803)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Recommended Answers

All 2 Replies

I have found the problem.
public Client getClient(){
person = new Client();
...
}

Nicely done, we would be able to help you as that wasn't part of the code and rest which you provided does look fine

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.