NoSuchMethodError: main
我对Java相当陌生,当我执行以下代码时,我无法弄清楚为什么我会得到。我不确定这与什么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);
}
}