Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 497845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:49:14+00:00 2026-05-13T05:49:14+00:00

I have this method but in run-time it will be thrown nullpointerexception,why? my method:

  • 0

I have this method but in run-time it will be thrown nullpointerexception,why?

my method:

public static boolean isAddBirth(String name, String family, String fatherName, String mName, String dOfBirth, String pOfBirth) {
    ResultSet rst;
    boolean bool = false;
    Statement stmt;
    try {
        stmt = conn.createStatement();



        rst = stmt.executeQuery("SELECT * FROM birthtable");


        while (rst.next()) {
            if (rst.getString(2).equals(name) && rst.getString(3).equals(family) && rst.getString(4).equals(fatherName) && rst.getString(5).equals(mName) && rst.getString(6).equals(dOfBirth) && rst.getString(7).equals(pOfBirth)) {
                bool = false;
            } else {
                bool = true;
            }
        }
    } catch (SQLException ex) {
        Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex);
    }
    return bool;




}

stacktrace:

java.lang.NullPointerException
    at database.Manager.isAddBirth(Manager.java:164)
    at AdminGUI.AddNewBornInformation.submit(AddNewBornInformation.java:356)
    at AdminGUI.AddNewBornInformation.setButtonActionPerformed(AddNewBornInformation.java:283)
    at AdminGUI.AddNewBornInformation.access$800(AddNewBornInformation.java:28)
    at AdminGUI.AddNewBornInformation$9.actionPerformed(AddNewBornInformation.java:140)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6038)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
    at java.awt.Component.processEvent(Component.java:5803)
    at java.awt.Container.processEvent(Container.java:2058)
    at java.awt.Component.dispatchEventImpl(Component.java:4410)
    at java.awt.Container.dispatchEventImpl(Container.java:2116)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
    at java.awt.Container.dispatchEventImpl(Container.java:2102)
    at java.awt.Window.dispatchEventImpl(Window.java:2429)
    at java.awt.Component.dispatchEvent(Component.java:4240)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

ALSO these are in my class:

Logger logger = Logger.getLogger(this.getClass().getName());
private static Connection conn = DBManager.getConnection();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:49:15+00:00Added an answer on May 13, 2026 at 5:49 am

    Given you didn’t provide line number 164 I’ll take a guess that it is:

    if (rst.getString(2).equals(name) && rst.getString(3).equals(family) && rst.getString(4).equals(fatherName) && rst.getString(5).equals(mName) && rst.getString(6).equals(dOfBirth) && rst.getString(7).equals(pOfBirth)) 
    

    First off that line makes me want to cry.

    Let’s fix it:

    String a;
    String b;
    String c;
    String d;
    String e;
    String f;
    
    a = rst.getString(2);
    b = rst.getString(3);
    c = rst.getString(4);
    d = rst.getString(5);
    e = rst.getString(6);
    f = rst.getString(7);
    
    if (!(a.equals(name))
    {
        bool = false;
    }
    
    if(!(b.equals(family))
    {
        bool = false;
    }
    
    if(!(c.equals(fatherName))
    {
        bool = false;
    }
    
    if(!(d.equals(mName))
    {
        bool = false;
    }
    
    if(!(e.equals(dOfBirth))
    {
        bool = false;
    }
    
    if(!(f.equals(pOfBirth))
    {
        bool = false;
    }
    

    That will at least show you the line that has the null pointer on it (assuming my guess is correct).

    Also, a-e are terrible names… you should pick better ones than I did.

    The real solution here is to use Object Oriented programming as it is intended… let’s make a Person class:

    public class Person
    {
        private final String firstName;
        private final String lastName;
        private final String middleName; // guessing that is what mName is...
        private final String fathersName;
        private final String dateOfBirth;
        private final String placeOfBirth; // guessing that is what pOfBirth is...
    
        public Person(final String firstName,
                      final String lastName,
                      final String middleName,
                      final String fathersName,
                      final String dateOfBirth,
                      final String placeOfBirth)
        {
            if(firstName == null)
            {
                throw new IllegalArgumentException("firstName cannot be null");
            }
    
            if(lastName == null)
            {
                throw new IllegalArgumentException("lastName cannot be null");
            }
    
            ... etc for all of the other arguments ...
    
            // I would never do the this.fristName thing.. .I would name the parameter different than the instance vairable...
            this.firstName = firstName;
            this.lastName  = lastName;
    
            ... etc for all of the other arguments ... 
        }
    
        public boolean equals(final Object o)
        {
            final Person person;
    
            if(!(o instanceof Person))
            {
                return (false);
            }
    
            other = (Person)o;
    
            // the code you I put above + your code for checking if they are equal
        }
    
        public int hashCode()
        {
            // this is probably good enough
            return (firstName.hashCode() + lastName.hashCode());
        }
    }
    

    Then in your method you would have code something like:

    rst = stmt.executeQuery("SELECT * FROM birthtable");
    
        while (rst.next()) 
        {
            final Person person;
    
            // I would use temp variables rather than passing in the result of getString directly...
            person = new Person(rst.getString(2),
                                rst.getString(3),
                                rst.getString(4),
                                rst.getString(5),
                                rst.getString(6),
                                rst.getString(7));
    
            // otherPerson would be passed into the method instead of the String you are passing now
            bool = person.equals(otherPerson);
    
            ... etc ...
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 270k
  • Answers 270k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think I would go with Redis, because: Antirediz(his nickname)… May 13, 2026 at 1:31 pm
  • Editorial Team
    Editorial Team added an answer I have a series of sample messages that I show… May 13, 2026 at 1:31 pm
  • Editorial Team
    Editorial Team added an answer You have to assign a prefix. Make that call addNamespace("hopfrog",… May 13, 2026 at 1:31 pm

Related Questions

I have a panel sitting in a div, and I want to use that
A method I work with that is called tens of thousands of times started
I need to create an instance of an object and the type of that
I know this sounds like a homework assignment, but it isn't. Lately I've been
Alright...I've given the site a fair search and have read over many posts about

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.