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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:57:00+00:00 2026-06-17T22:57:00+00:00

I am playing around with java, and have run into an issue when I

  • 0

I am playing around with java, and have run into an issue when I utilize custom constructors.

When I begin my program, the main file contains a line like this:

Word input = new Word(word);

The constructor for word looks like this:

public Word(String s){
        wordArray = s.toCharArray(); 
        protocol = new Protocol(wordArray.length);
    }

And the protocol looks like this:

public Protocol(int length)
    {
        letterList[0] = 'a';
        letterList[1] = 'b';
        letterList[2] = 'c';
        letterList[3] = 'd';
        letterList[4] = 'e';
        letterList[5] = 'f';
        letterList[6] = 'g';
        letterList[7] = 'h';
        letterList[8] = 'i';
        letterList[9] = 'j';
        letterList[10] = 'k';
        letterList[11] = 'l';
        letterList[12] = 'm';
        letterList[13] = 'n';
        letterList[14] = 'o';
        letterList[15] = 'p';
        letterList[16] = 'q';
        letterList[17] = 'r';
        letterList[18] = 's';
        letterList[19] = 't';
        letterList[20] = 'u';
        letterList[21] = 'v';
        letterList[22] = 'w';
        letterList[23] = 'x';
        letterList[24] = 'y';
        letterList[25] = 'z';
        wordLength = length;
        for(int i=0;i<wordLength*2-1;i++)
        {
            display[i] = '_';
            i++;
            display[i] = ' ';
        }
    }

I am getting a NullPointerException at the line within my main file where word is constructed, and then protocol .

I have experimented with the code, and noticed if I do not call the constructor for the protocol within word the build is successful past that point, but I need protocol to be built later as well, so it still has issues.

Am I not allowed to call a constructor within another constructor? Anyone have any ideas on what may be going on?

If you need more clarification, please let me know!

  • 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-06-17T22:57:01+00:00Added an answer on June 17, 2026 at 10:57 pm

    Am I not allowed to call a constructor within another constructor?

    No, you are definitely allowed to do that.

    Anyone have any ideas on what may be going on?

    Clearly, word is null when passed to the Word constructor at this line:

    Word input = new Word(word);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Completely new to java and I have been playing around with regex in a
I am currently learning about basic networking in java. I have been playing around
I am just playing around with threads in java. I have a class which
I'm playing around with java and came across the following problem. I have the
New to Android/Java, and I'm playing around with AddProximityAlert(). I have the following block
I have been playing around with zxing over the weekend, and have ran into
I´ve just started playing around with Java and Hibernate and have gotten an application
Lately I have been playing around with Java's ScriptEngine API, namely the javascript engine,
I have been playing around with node.js, and coming from a Java background, I
I'm just getting the hang of OOP and have been playing around with Java

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.