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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:43:46+00:00 2026-06-15T19:43:46+00:00

Evening everyone. I seem to have hit an odd problem when trying to pass

  • 0

Evening everyone.

I seem to have hit an odd problem when trying to pass an object to another objects constructor who’s constructor also relies on the object it’s being passed to.

For instance, take the example below:

ToolBar myToolBar = new ToolBar(webPanel);
WebPanel webPanel = new WebPanel(myToolBar);

However when constructing ToolBar it returns a NullPointerException. Ofcourse that’s because webPanel isn’t constructed yet and it requires it.

Both of the decelerations and initialization must remain in the same class (called BuildUI) since it’s where I set up the properties. (It also doesn’t make sense for a ToolBar to create a webPanel object and vice versa).

I’m also not sure if that’s even good programming practice, since both objects require references to each other.

Any advice here is much appreciated. Thanks, Tom.

  • 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-15T19:43:48+00:00Added an answer on June 15, 2026 at 7:43 pm

    This will lead to problems as you can see. Instead of this approach, you can use the setter-getter method approach where you construct the object with a default constructor such as

    ToolBar myToolBar = new ToolBar();
    WebPanel webPanel = new WebPanel();
    

    and then use the setter methods to set the required instance variables which are required for the object to be fully constructed.

    myToolBar.setWebPanel(webPanel);
    webPanel.setToolBar(myToolBar);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening everyone. I am currently using MVC 3 and I have a viewmodel
Evening :) I have a little problem... As you can see in my code
Good evening everyone, I am currently trying to cleanup my inline JS and break
Good morning\evening everyone! i have a string in a format like 0x0SD30SV8GN48N84GN wich represent
Evening folks, I have a complex MySQL COUNT query I am trying to perform
Good evening everyone, before explaining my problem, I should give you some explanation on
Good evening everyone! I am having a bit of a problem and need some
Good evening everyone! I am working on learning some java and I have made
Good Evening everyone, I've been trying to figure out the most efficient way to
Good evening, everyone. I've now run into an odd warning, and for the life

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.