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

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站