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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:45:01+00:00 2026-05-24T02:45:01+00:00

This is the constructor of my class . With the following code : public

  • 0

This is the constructor of my class . With the following code :

public tester {
    setTitle("tester");
    initComponents();
    jTextArea6.setEditable(false);
    jEditorPane1.setEditable(false);
}

Every thing is fine . But with this code ,

public tester() {
    setTitle("tester");
    jTextArea6.setEditable(false);
    jEditorPane1.setEditable(false);
    initComponents();

}

i get the following exceptions :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at tester.tester.<init>(tester.java:31)
at tester.tester$35.run(tester.java:1389)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:660)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Why this is so ?

  • 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-24T02:45:01+00:00Added an answer on May 24, 2026 at 2:45 am

    Without seeing the rest of the code (the definition of initComponents in particular, plus the definition of the fields) it’s not possible to be 100% certain.

    But it’s almost definitely the case that the initComponents() method sets the value of jTextArea6 and/or jEditorPane1. In the second example you’re trying to dereference these fields before they’re set; which means they’d have the default value of null, and so would cause the NullPointerException to be thrown when you try to invoke methods on them.

    Obviously one fix is to leave things as they are, perhaps with a comment stating

    // Note - this method call initialises the fields.  DO NOT REORDER!!!
    

    But a better solution is to get the compiler to check these things for you. If the two fields don’t ever change (i.e. they’re set up once and for all within the constructor), then you can and arguably should declare them final. In addition to this being very clear to others that they don’t have to consider the possibility of these fields changing, it means that they won’t have default values assigned initially, and the compiler will not let you dereference them before they’ve been assigned.

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

Sidebar

Related Questions

I have a varargs constructor like this : public class Sentence { public String[]
I have non-template class with a templatized constructor. This code compiles for me. But
I have a constructor question for C#. I have this class: public partial class
I have the following code: public static class ScraperMasterUriDetails { public static Dictionary<Guid, string>
I just got to read the following code somewhere : public class SingletonObjectDemo {
I'm curious about the following code: class MyClass { public: MyClass() : _myArray(new int[1024])
I have following class in Java code: public class CHRTreeCreator extends IndexCreator { ...
I have the following code: public abstract class BaseController : Controller { public IUserService
I've the following code in my displayandmove.as file: package { import flash.display.MovieClip; public class
Consider the following code: class CString { private: char* buff; size_t len; public: CString(const

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.