954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help pls

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)
kapkan
Newbie Poster
5 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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

kapkan
Newbie Poster
5 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You