//我用的eclipsepackage Chapter10;  //这里有提示说A class file was not written......然后就无法run,请问是为什么?下面的代码都没报错了。public class producor { public static void main(String[] args) {
quantity q=new quantity();
new Pro(q);
new con(q);
System.out.println("a a a");
}}
class quantity
{
int n;
boolean b=false;
synchronized int get()
 {
 if(!b)
 try{
 wait();
 }catch(InterruptedException e){
 System.out.println("catch");
 }
 System.out.println("a"+n);
 b=false;
 notify();
 return n;
 }
synchronized void put(int n)
 {
if(b)
try
    { 
wait();
}catch(InterruptedException e){
System.out.println("put errors");
}
this.n=n;
b=true;
 System.out.println("put"+n);
 notify();
 }
}
class Pro implements Runnable
{
quantity q;
Pro(quantity q)
{
this.q=q;
new Thread(this,"Pro").start();
}
public void run() {
int i=0;
while(true)
{
q.put(i++);
}

}

}
class con implements Runnable
{
quantity q;
con(quantity q)
{
this.q=q;
new Thread(this,"con").start();
}
public void run()
{
while(true)
{
q.get();
}
}
}

解决方案 »

  1.   

    你的文件名叫 
    producor.java吗?
    放在了
    src/Chapter10/目录下面吗?
      

  2.   

    对,eclipse里对路径要求很严,首先检查路径是否正确
      

  3.   

    在src/Chapter10/下了,名字正确,我检查了下。
    在thread\bin\Chapter10这个目录下少一个CLASS文件,就是con类的,不知道为什么没出来,请问这是为什么?要怎么改?
      

  4.   

    你在IDE里面运行的吧!那个提示应该只是一个警告吧!你可以忽略他继续运行的!
      

  5.   

    老紫竹那么早啊,辛苦了,大过年的。
    少了一个CLASS文件也可以运行么?但是ECLIPSE是报错了。
    Exception in thread "main" java.lang.NoClassDefFoundError: Chapter10/con
    at Chapter10.producor.main(producor.java:8)
    Caused by: java.lang.ClassNotFoundException: Chapter10.con
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 1 more
    put0
      

  6.   

    class   con   implements   Runnable 你的文件里面有这个类,难道他没有编译吗? 你看看是否有编译错误?
      

  7.   

    真可惜,经过我的测试,con 竟然和某些类冲突,所以你需要把
    con 改成其他的名字,比如mycon 就可以了!我再去查一下为什么这样!
      

  8.   

    con是DOS保留字,好象是一设备,WINDOWS也是建立在DOS基础上的。
    所以,不能再windows下面创建名字为con/Con,CON 的类!哈哈哈!我都忘了这个问题了,还有一些其他的类名也不能建立con是操作系统保留的一个设备名字,还有很多设备名都不能拿来用,如下:   
        
      The   following   reserved   device   names   cannot   be   used   as   the   name   of   a   file:   CON,   PRN,   AUX,   CLOCK$,   NUL,   COM1,   COM2,   COM3,   COM4,   COM5,   COM6,   COM7,   COM8,   COM9,   LPT1,   LPT2,   LPT3,   LPT4,   LPT5,   LPT6,   LPT7,   LPT8,   and   LPT9.   Also   avoid   these   names   followed   by   an   extension   (for   example,   NUL.tx7).     
      

  9.   

    呵呵 改名的时候才看见了更明确的提示con is an invalid name on this platform.