当前位置: 代码迷 >> J2SE >> in thread "main" java.lang.NoSuchMethodError: main
  详细解决方案

in thread "main" java.lang.NoSuchMethodError: main

热度:395   发布时间:2016-04-24 18:12:53.0
初级线程异常问题
以下这段代码是哪里出错吗???怎么会出现这种异常呢??
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 当普通的函数编译
 
  相关解决方案