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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:13:11+00:00 2026-05-27T04:13:11+00:00

Possible Duplicate: Exception in thread “main” java.lang.NoSuchMethodError: main I am fairly new to Java,

  • 0

Possible Duplicate:
Exception in thread “main” java.lang.NoSuchMethodError: main

I am fairly new to Java, and I am unable to figure out why I am getting NoSuchMethodError: main when I execute the following code. I am not sure what does the NoSuchMethodError is pertaining to. It looks like I have everything right. Please help me out here. Thanks a lot.

public class ThreadExample1 extends Thread 
 {
    static String[] msg = {"Java", "programming", "is", "the", "best"};
    public ThreadExample1(String id) 
    {
       super(id);
     }
    @Override
    public void run() 
        {
         try 
           {
             Output.displayList(getName(), msg);
            } 
    catch (InterruptedException ex) 
        {

        }
    }
  }

class Output 
 {
  public static void displayList(String name, String list[]) throws InterruptedException 
   {
     for (int i = 0; i < list.length; i++) 
    {
          Thread.currentThread().sleep((long) (3000 * Math.random()));
          System.out.println(name + list[i]);
         }
    }
   public static void main(String[] args) 
    {
         ThreadExample1 thread1 = new ThreadExample1("thread1: ");
         ThreadExample1 thread2 = new ThreadExample1("thread2: ");
         thread1.start();
         thread2.start();
         boolean t1IsAlive = true;
         boolean t2IsAlive = true;
         do 
          {
          if (t1IsAlive && !thread1.isAlive()) 
            {
              t1IsAlive = false;
              System.out.println("t1 is dead.");
             }
          if (t2IsAlive && !thread2.isAlive()) 
            {
              t2IsAlive = false;
              System.out.println("t2 is dead.");
              }
           }while (t1IsAlive || t2IsAlive);
     }
}
  • 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-27T04:13:11+00:00Added an answer on May 27, 2026 at 4:13 am

    I don’t have any problem compiling and executing the above code … Keep in mind that when you want to execute it , you need to use this command line :

    java Output
    

    and NOT :

    java ThreadExample1
    

    because the main method is within the Output calss and not in ThreadExample1 …

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

Sidebar

Related Questions

Possible Duplicate: Exception in thread “main” java.lang.NoSuchMethodError: main My main syntax is correct. What
Possible Duplicate: Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”' i got this error
Possible Duplicate: Causes of 'java.lang.NoSuchMethodError: main Exception in thread “main”' I am using Eclipse.
Possible Duplicates: Exception in thread “main” java.lang.NoClassDefFoundError: DiServer <wrong name: ds/DiServer> java.lang.NoClassDefFoundError when i
Possible Duplicate: “Cross-thread operation not valid” exception on inner controls I am a beginner
Possible Duplicate: Using global exception handling with “setUncaughtExceptionHandler” and “Toast” I have implemented UncaughtExceptionHandler
Possible Duplicate: Getting exception as “Collection was mutated while being enumerated” This question is
Possible Duplicate: difference between throw and throw new Exception() I'm a programmer working on
Possible duplicate: why-is-java-lang-throwable-a-class Hi! I doesn't understand why Throwable isn't abstract class. I see
Possible Duplicate: catch exception by pointer in C++ I always catch exceptions by value.

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.