问答详情
源自:2-4 Java线程-隋唐演义实战开发---军队

我跟着老师打的,为什么会出错?

Thread armyOfDynasty = new Thread(armyTaskOfSuiDynasty, "隋军");

//这句出错,错误:   The constructor Thread(ArmyRunnable, String) is undefined

Thread armyOfRevolt = new Thread(armyTaaskOfRevolt, "农民军");

//这句同上错误

armyOfDynasty.start();

armyOfRevolt.start();

try {

Thread.sleep(50);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

armyTaskOfSuiDynasty.keepRunning = false;//这句出错,错误是:keepRunning cannot be                                                                             //resolved or is not a field

armyTaaskOfRevolt.keepRunning = false;//这句同上


提问者:慕粉4206482 2016-11-08 11:03

个回答

  • 孙胖子的初始之路
    2016-11-25 04:33:34

    你有书吗?再看一下关于runnable线程的创建,你必须得先创建Runnable接口实现类的实例再创建Thread线程呀

  • 慕码人3499322
    2016-11-08 19:51:49

    上面肯定少了东西,仔细检查