Quando tento rodar o seguinte código surge esse erro:
Exception in Thread “main” java.lang.NoSuchMethodError: main
Onde está o erro?
class Q {
int n;
synchronized int get() {
System.out.println("Obtive: "+n);
return n;
}
synchronized void put(int n) {
this.n = n;
System.out.println("Pus: "+n);
}
}
class Produtor implements Runnable {
Q q;
Produtor(Q q) {
this.q = q;
new Thread(this, "Produtor").start();
}
public void run() {
int i = 0;
while(true) {
q.put(i++);
}
}
}
class Consumidor implements Runnable {
Q q;
Consumidor(Q q) {
this.q = q;
new Thread(this, "Cosumidor"). start();
}
public void run() {
while(true) {
q.get();
}
}
}
class PC {
public static void main(String args[]) {
Q q = new Q();
new Produtor(q);
new Consumidor(q);
}
}
[size=“11”][color=“green”]* Use BBCode ao postar algum código - matheus[/color][/size]
