当我运行该程序时,它不显示“HIIII”。 我是一个新手(某种程度上),所以请不要“讨厌”。 我的 wait() 语句是否错误?或者我做错了什么? 是 ArrayIndexOutOfBounds catch 子句吗?请帮忙!
[edit]
哦,这是主要方法吗?它什么也没做?
[edit]
我知道等待和通知是错误的......请不要提及它。
//this is the whole class
import javax.swing.*;
import javax.swing.JOptionPane;
public class none {
static boolean game;
final static boolean on = true;
final static boolean off = false;
static boolean cheatMode;
public static void main(String[] args) {
game = on;
boolean tru = true;
try{
if(tru = Boolean.parseBoolean(args[0])){
cheatMode = on;
System.out.println("Cheats are on.");
}
}
catch(java.lang.ArrayIndexOutOfBoundsException e){
e.printStackTrace();
System.out.println("Ignore this error, it's from not running it on the command prompt.");
}
}
public class console extends Thread{
public void run(){
try{
wait();
JOptionPane.showMessageDialog(null,"HIIII");
}
catch(Exception e){
e.printStackTrace();
System.out.println("The console glitched...");
}
//hiiii
JOptionPane.showMessageDialog(null,"HIIII");
}
public class mainThingy extends Thread{
public void run() {
if(game = on)
notify();
}
}
}
}
最佳答案
似乎有几个问题
1) if(tru = Boolean.parseBoolean(args[0])){
以上语句是赋值而不是比较。使用 == 运算符。
2) 等待和通知应始终从 Synchronized block 内部调用。您的代码似乎没有这样做。
关于catch 子句之后的 java wait() 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12833450/