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 7607569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:41:50+00:00 2026-05-31T00:41:50+00:00

Working on a search method for my doubly linked list. I’m getting exceptions but

  • 0

Working on a search method for my doubly linked list. I’m getting exceptions but I can’t seem to figure out how to traverse the list without getting them..

    public void searchEntryNode() {
    System.out.println("I'll search through each entry to pull up what you're looking for ");
    System.out.println("Type in what you want ");
    String searchEntry = keyboard.next();

    EntryNode n = head;
    while (head != null) {
        if (head.getFirstName().contains(searchEntry) || head.getLastName().contains(searchEntry) || head.getPhoneNum().contains(searchEntry) || head.getEmail().contains(searchEntry)) { 
            System.out.println("Found a matching entry");
            System.out.println(n.getFirstName() + " " + n.getLastName() + " " + n.getEmail() + " " + n.getPhoneNum());
        }

        if (head.getNext() != null) {
            head = head.getNext();
        }   
        else {
                System.out.println("That's all we found ");
                System.out.println();
                menu();
        }
    }
}
  • 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-31T00:41:51+00:00Added an answer on May 31, 2026 at 12:41 am

    I don’t have your line counts, so I’m guessing blindly here, but I’m going to guess that this line is your problem:

    if (head.getFirstName().contains(searchEntry) || head.getLastName().contains(searchEntry) || head.getPhoneNum().contains(searchEntry) || head.getEmail().contains(searchEntry))
    

    It’s probable that one of your entries returns null for either getFirstName, getLastName, getPhoneNum, or getEmail.

    You will have to check each is not null before dereferencing (you can’t do null.someMethod())

    One way of doing this:

    string firstName = head.getFirstName();
    string lastName = head.getLastName();
    string phoneNum = head.getPhoneNum();
    string email = head.getEmail();
    
    if ((firstName != null && firstName.contains(searchEntry)) 
         || (lastName != null && lastName.contains(searchEntry)) 
         || (phoneNum != null && phoneNum.contains(searchEntry)) 
         || (email != null && email.contains(searchEntry)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with Facebook API and it's search method returns a JSON response like
HI I have a working SmsReceiver and a method that will search to contacts
Greetings, I already have a working connection to the AD and can search and
I'm working on a c# jquery implementation and am trying to figure out an
The big picture: I'm working on a search form where the user can choose
Am working on web based Job search application using Lucene.User on my site can
I can't figure out why this regex doesn't work, I've tested it in php
I'm working on a hybrid data structure that is an ordered double-linked list where
I am trying to put full text search working on SQL Server 2008, however
I am altering the question now! I have the search working using the following:

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.