日期:2014-05-20  浏览次数:20846 次

初级线程异常问题
以下这段代码是哪里出错吗???怎么会出现这种异常呢??
Exception in thread "main" java.lang.NoSuchMethodError: main




class mythread implements Runnable
{
private String name;
private int time;
public mythread(String name,int time){
this.name=name;
this.time=time;
}
public void run(){
try{
Thread.sleep(this.time);
}catch(InterruptedException e){
e.printStackTrace();
}
System.out.println(this.name+"运行,休眠"+this.time+"毫秒");
}
}
public class oo2
{
public static void mian(String args[]){
mythread my1=new mythread("线程A",10000);
mythread my2=new mythread("线程B",20000);
mythread my3=new mythread("线程C",30000);
new Thread(my1).start();
new Thread(my2).start();
new Thread(my3).start();
}
}

------解决方案--------------------
public static void mian(String args[]){

天啊,楼主认真点……main写成mian了
------解决方案--------------------
缺少主方法main

class mythread implements Runnable
{
 private String name;
 private int time;
 public mythread(String name,int time){
 this.name=name;
 this.time=time;
 }
 public void run(){
 try{
 Thread.sleep(this.time);
 }catch(InterruptedException e){
 e.printStackTrace();
 }
 System.out.println(this.name+"运行,休眠"+this.time+"毫秒");
 }
}
public class oo2
{
 public static void main(String args[]){
 mythread my1=new mythread("线程A",10000);
 mythread my2=new mythread("线程B",20000);
 mythread my3=new mythread("线程C",30000);
 new Thread(my1).start();
 new Thread(my2).start();
 new Thread(my3).start();
 }
}

这样试下

public static void main(String args[]) 改下这行 
原来写的mian 当普通的函数编译