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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:10:48+00:00 2026-05-24T00:10:48+00:00

I have a Class MyClass, that when it runs it initialize a GUI awt

  • 0

I have a Class MyClass, that when it runs it initialize a GUI awt frame (“Launch.java“), by calling the GUI’s main method.
in this main method i have EventQueue.invokeLater whose runnable actually does all the initialization. One part of the initialization is to set an object called “controller“.

After calling the GUI’s main method from MyClass, I want to getController() the controller, but it returns null, and I don’t know why.

when i debugged it i put a breakpoint in Launch.java on the line where controller is created (controller = new Controller(textArea)), and i noticed that it is not null then, but back in MyClass it is null when I call Launcher.getController().

What am I doing wrong?? Thanks!

MyClass:

public class MyClass{

private static boolean isInitialized = false;
private Controller control;

public static void main(String[] args){

    if (!isInitialized)
    {
        Launch.main(new String[1]);
        control = Launch.getControl(); //here control is null!
        isInitialized = true;
    }
    //irrelevant code here      
}
}}

Launch.java:

public class Launch {

private JFrame frame;
private JTextField inputField;
DefaultListModel model;
private static Controller controller;
JSpinner spinner;

public static Controller getControl()
{
    return controller;
}


/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Launch window = new Launch();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

public Launch() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
        //some code here... (here controller is null)

        controller = new Controller(textArea);

        //some code here...  (here controller is not null - during debug)
    }
}
  • 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-24T00:10:49+00:00Added an answer on May 24, 2026 at 12:10 am

    There are several problems with your code. The most glaring is that you invoke main() and then getControl() synchronously on the servlet thread. However the code that creates the controller is invoked at some indeterminate future time, assuming the existence of an AWT dispatcher thread and system event queue. At the time you invoke getControl() the Launch object has most likely not been instantiated.

    Assuming the rest of your code does what you want, what you need to do is move the invocation of getControl() to just before you use its return value.

    I’m answering only the question you asked… however the design of your app (launching an AWT app from a servlet, the missing AWT event loop code, etc) looks questionable.

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

Sidebar

Related Questions

Currently I have a class that looks like this: public class MyClass : IMyClass
I have a class with two constructors that look like this: public MyClass(SomeOtherClass source)
I have a class that looks like the following: public class MyClass { private
I have a class that inherits from a generic dictionary as follows: Class myClass
I have a class that implements IComparable. public class MyClass : IComparable<MyClass> { public
I have a class that subclasses NSMutableArray. I init it using: MyClass class =
I have a generic class public MyClass<TContext, T> where TContext : DataContext that effectively
I have a list of class items List<MyClass> I have a seperate object that
in my Silverlight 4 application, I have a class myClass that contains a list
I have a class MyClass that has a static variable. Class implements smth like

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.