Can Someone help me I\'m getting a Nullpointer exception Line 544 is int result
ID: 3818171 • Letter: C
Question
Can Someone help me I'm getting a Nullpointer exception
Line 544 is
int result = personQueries.addPerson(firstNameTextField.getText(),
lastNameTextField.getText(), emailTextField.getText(),
phoneTextField.getText());
Its right before main
personQueries is another class
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at addressbookdisplay.AddressBookDisplay.insertButtonActionPerformed(AddressBookDisplay.java:544)
at addressbookdisplay.AddressBookDisplay.access$500(AddressBookDisplay.java:45)
at addressbookdisplay.AddressBookDisplay$6.actionPerformed(AddressBookDisplay.java:354)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
Explanation / Answer
Since the code provided is an image and not text, so its not possible to copy the code and do correction.
So I am just providing you with what looks like the root cause of this error.
You are using a personQueries object in your AddressBookDisplay class. But no where in your construct you have initialized and allocated memory to personQueries object. So when you are trying to access a member function addPerson of personQueries , it gives NullPointer exception, since personQueries object has not been allocated memory and is a nullpointer.
To fix this, you need to allocate the personQueries object with memory in your constructor of AddressBookDisplay , somewhat like below
personQueries = new PersonQueries ();
I hope this helps.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.