longrenli165_jack 2015-06-10 09:45 采纳率: 0%
浏览 2418

多线程测试类,运行找不到main方法,求大神洞悉问题

public class hello {

static class hello1 extends Thread {

    public hello1() {

    }

    public hello1(String name) {
        this.name = name;
    }

    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(name + "运行     " + i);
        }
    }


    public static void main(String[] args)
    {     
 hello1 h1=new hello1("A");
 hello1 h2=new hello1("B");
 h1.run();
 h2.run();
}

private String name;

}
}

错误信息如下:
错误: 在类 hello 中找不到 main 方法, 请将 main 方法定义为:
public static void main(String[] args)
否则 JavaFX 应用程序类必须扩展javafx.application.Application

——————————————————————————————————————————————————————————————————————
多谢各位!还有个问题,如果把hello1这个thread类的 static去掉,主函数中就找不到它了,必须加static是吗?

  • 写回答

5条回答 默认 最新

  • danielinbiti 2015-06-10 09:49
    关注
     public class hello {
    static class hello1 extends Thread {
    
        public hello1() {
    
        }
    
        public hello1(String name) {
            this.name = name;
        }
    
        public void run() {
            for (int i = 0; i < 5; i++) {
                System.out.println(name + "运行     " + i);
            }
        }
    
    
    
    
    private String name;
    }//--这里是thread类,也就是hello1类
    public static void main(String[] args)
        {     
     hello1 h1=new hello1("A");
     hello1 h2=new hello1("B");
     h1.run();
     h2.run();
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大