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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:13:14+00:00 2026-05-23T07:13:14+00:00

I am trying to reference a setter… I received help and selected the answer

  • 0

I am trying to reference a setter… I received help and selected the answer too soon before resolving the issue…. see here: Using a setter from outside a form?

So, what I’m doing is this… Data goes into the log and it gets parsed, then it goes back to the form where it is displayed.

public class Log {
   private MainForm mainForm; // our MainForm variable

   public Log(MainForm mainForm) {
      // setting the MainForm variable to the correct reference in its constructor
      this.mainForm = mainForm;  
   }

   private  void consoleOut(String data) {
     System.out.println(data);
     if (mainForm != null) {
        // now we can use the reference passed in.
        mainForm.setConsoleText("data");
     }
   }
}

Here’s the setter in my form.

public class MainForm extends FrameView {
    public MainForm(SingleFrameApplication app) {
        super(app);
...........CUT FOR LENGTH.................
    public void setConsoleText(String Text){
        jTextArea2.append(Text);
    }

edited for simplicity sake.

For some reason MainForm always comes out null in the Log class.

How can I get a reference to my Main form?

Meh… I just went with a static textbox and a static setter…. Still looking for a better idea.

  • 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-23T07:13:15+00:00Added an answer on May 23, 2026 at 7:13 am

    The only explanation is that when you are instantiating Log you are passing a null to the constructor. Are you calling new Log(mainform) before mainform has been assigned?

    // Don't do this
    private Log log = new Log(mainForm);
    
    private MainForm mainForm = new MainForm();
    

    Check the order of construction of your objects.

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

Sidebar

Related Questions

I am trying to reference the jQuery library in my master page like so:
We are trying to reference a certificate for a client endpoint configuration in our
I am trying to reference some child entities with part of the parents composite
In the below code, i am trying to reference an external .dll, which creates
I've got a GWT 1.6 project in Eclipse 3.4 and am trying to reference
I'm getting a Can't use an undefined value as a HASH reference error trying
Trying the ggplot2 examples in the online reference manual, and particularly in this page
Trying to use an excpetion class which could provide location reference for XML parsing,
I am trying to add a project reference or swc to papervision in FlashDevelop
I'm trying to add a Web Reference to a VS2008 .Net 3.5 Console Application

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.