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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:24:33+00:00 2026-05-16T12:24:33+00:00

When I am inside the constructor of a managed and trying to reach out

  • 0

When I am inside the constructor of a managed and trying to reach out to other methods from other beans, I got java.lang.NullPointerException. Is there some kind of specification that not allow managed bean to do that?

@ManagedProperty(value="#{document}")
private DisplayListController document;

@EJB
DocumentSBean sBean;

public NewUserController() {
    document.list();
} 

Above I just do regular bean injection, nothing fancy. document is a SessionScoped managed bean that has method list() which just return a String. NewUserController is a RequestScoped managed bean.

  • 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-16T12:24:33+00:00Added an answer on May 16, 2026 at 12:24 pm

    You should look into @PostConstruct. An example can be found here.

    Your properties are not being set when you’re trying to access them. You need to wait for them to be set. Bean management typically goes:

    1. Create Beans
    2. Set Properties

    You’re trying to use properties that have not been set, thus resulting in your NPE.

    So your code could change to:

    public NewUserController() { }
    
    @PostConstruct
    public void init() {
        document.list();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way, to change the field's *min_length* argument inside form constructor? That
Why cant we initialize Const and reference varibales inside the constructor braces({ }) and
As an abstract class cannot be instantiated, why is a constructor still allowed inside
In C++, the lifetime of an object begins when the constructor finishes successfully. Inside
Inside a windows batch file I'd like to figure out what the fully qualified
take a look at the following code I attempted to write inside a constructor:
I have to initialize file objects inside the constructor and for handling the exception,
Why is HttpContext.User.Identity.IsAuthenticated throwing System.NullReferenceException in the base controller from where all my other
Can I declare parameterized constructor inside servlet which is only constructor ? If no
Is there any way to make private variables (those defined in the constructor), available

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.