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

  • Home
  • SEARCH
  • 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 7192755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:00:42+00:00 2026-05-28T20:00:42+00:00

Hoping you guys can figure out why im getting a null pointer exception with

  • 0

Hoping you guys can figure out why im getting a null pointer exception with what I can provide, the program has several classes and method but this is the one that is breaking.

public void search(Node node, String sData, int iData)
{
    if (sData.equals(node.getString()) && (iData == node.getInt()))
    {
        System.out.println("Nailed it");
    }else if (sData.compareTo(node.stringData) < 0)
    {
        search(node.left, sData, iData);
    }else if (sData.compareTo(node.stringData) > 0)
    {
        search(node.right, sData, iData);
    }

}

the Node that is getting input at first is the root and then it goes left or right from there through recursion, but the line that says its erroring is the if statement up top. Cannot figure out what is wrong sData is just a standard string input when the method is called and iData is just an int thats input as well. Cannot figure it out =/ thanks for any help

  • 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-28T20:00:44+00:00Added an answer on May 28, 2026 at 8:00 pm

    You need to add the following at the top of your method:

    if (node == null) return;
    

    This would ensure that the method returns gracefully if you search for something that doesn’t exist in the structure. Otherwise with your existing code, you’ll encounter NullPointerExceptions when the method encounters leaf nodes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hoping someone can provide an answer with this, although it's not 100% programming related.
hoping you guys can help - I have a timestamp column in my db
hey guys, how can I just achieve this simple layout? I'm hoping the answer
I have another error, unexpected type required:variable found:value and I can't figure out why.
A little stumped by this one so I'm hoping you guys can help. Looks
Hoping someone can help me with a slight hurdle I've come up against in
Hoping some learned Rails developers here can recommend an existing Ruby on Rails plugin
Hoping someone can shed some light on this: Do lookup tables need their own
Hoping someone can point me in the right direction. I'm building a online shop
im hoping someone can help me quickly with a question i have. As site

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.