Possible Duplicate:
Exception in thread “main” java.lang.NoSuchMethodError: main获取“线程中的异常”main“java.lang.NoSuchMethodError:main”?
我是相当新的Java和我无法弄清楚为什么我收到NoSuchMethodError: main
当我执行下面的代码。我不确定NoSuchMethodError
是属于什么。看起来我拥有一切权利。请帮我在这里。非常感谢。
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);
}
}
你在命令提示符下尝试的内容; java的ThreadExample1或Java输出? – Naved
如果您正在运行'java ThreadExample1'的一些变体,那么这很有意义,因为'main'在'Output'中。如果你正在运行'java output',那么有些东西很奇怪,因为这应该是有效的。 –
@Naved:我在做javac ThreadExample1.java(即文件名)。然后,我正在做java ThreadExample1 – indolent