//我用的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();
}
}
}
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();
}
}
}
解决方案 »
- 有用过DatagramSocket的setReuseAddress()方法的朋友指定一下
- 实例化初始器,大家听过吗?有用吗?
- 怎么才能学好java哪?
- 找错题 看看这段代码中哪里有错误,先谢谢帮助菜鸟的老鸟们~~~
- (紧急)怎样加载第三方包(是zip 格式的)
- 关于编译器的问题
- 为什么在eclipse中修改了项目而在运行后页面中没改
- 请问有什么java的编译器?
- 如何在客户端运行cmd啊
- 新手小问题求解答
- 如何获得网页中指定的文本的字号?(100分)
- 【新手提问】一个折磨了我两天整的问题,拿出一半家产出来求救.为什么JScrollPane放在本内的JFrame和JPanel里可以显示.返回给别的类不行
producor.java吗?
放在了
src/Chapter10/目录下面吗?
在thread\bin\Chapter10这个目录下少一个CLASS文件,就是con类的,不知道为什么没出来,请问这是为什么?要怎么改?
少了一个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
con 改成其他的名字,比如mycon 就可以了!我再去查一下为什么这样!
所以,不能再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).