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();
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘