0

Sorry if this question stupid but i am trying to learn java and do some tuts on Swing. On all the tuts it is demonstrated on how to use the EventQueue.invokelater Method and pass it a Runnable object and override the run Method of it.

Code of one example looks as follows:

   public static void main(String[] args) {
    Runnable test = new Runnable ();
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            Guitest ex = new Guitest();
            ex.setVisible(true);
        }
    });

While running the code n eclipse it always tells me:

The method invokeLater(Runnable) in the type EventQueue is not applicable 
    for the arguments (new Runnable(){})

Why doesnt it accept the method as argument? What am a missing? Thanks in advance.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
m0lari
  • 1
  • 1
  • The argument should be accepted, however the line above it, `Runnable test = new Runnable();` is invalid as `Runnable` cannot be instantiated that way. – Jorel Ali May 29 '16 at 16:57
  • The first `new Runnable()..` should be like the 2nd, and **define the `run()` method.** – Andrew Thompson May 29 '16 at 17:15
  • the test object was just for testing purposes, sorry. However the argument isnt accepted even without it. also tried that one: `public static void main(String[] args) { Runnable test = new Runnable() { @Override public void run() { Guitest ex = new Guitest(); ex.setVisible(true); } };` EventQueue.invokeLater(test); } still not accepting as argument. – m0lari May 29 '16 at 17:42
  • Maybe the "official" oracle guide can help you out learning about concurrency in java: https://docs.oracle.com/javase/tutorial/essential/concurrency/index.html – licklake May 30 '16 at 08:43

0 Answers0