Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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)

import java.awt.event. ActionEvent; import java.awt.event. ActionListener; import java. awt.event. WindowAdapter; import java.awt.event. WindowEvent; import java.awt.FlowLayout; import java awt.GridLayout; import java.util.List; import javax.swing. JButton; import javax.swing. Box; import javax.swing.JFrame; import javax.swing.JLabel; import javax. swing. JPanel; import javax.swing. JTextField; import javax swing. WindowConstants; import javax.swing. BoxLayout import javax. swing. BorderFactory import javax swing. JOptionPane; public class AddressBookDisplay extends JFrame private Person currentEntry; private PersonQueries personQueries; private List

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote