我有一个GUI应用程序,它在通过控制台启动时工作正常。如果我通过双击启动jar,它会很好地开始,但在某些时候,可能是,从jar中读取序列化对象时,它会停止。
相关代码:
public static void nashEQ() {
if(!running){
running = true;
Generator.generateTables();
int u0 = Generator.handRanks[53 + Board[0]];
int u1 = Generator.handRanks[u0 + Board[1]];
int u2 = Generator.handRanks[u1 + Board[2]];
int u3 = Generator.handRanks[u2 + Board[3]];
int u4 = Generator.handRanks[u3 + Board[4]];
distributionOne.setProbabilities();
distributionTwo.setProbabilities();
distributionOne.SetRelativeProbabilities(distributionTwo);
distributionTwo.SetRelativeProbabilities(distributionOne);
distributionOne.setRanks(u4);
distributionTwo.setRanks(u4);
DecisionNode d = createGame();
double[] p1 = distributionOne.getProbabilities();
double[] p2 = distributionTwo.getProbabilities();
for (int i = 0; i <= MaxIteration; i++) {
d.trainVanilla(0, p1, p2);
d.trainVanilla(1, p2, p1);
CurrentIteration = i;
}
// double br0 = d.bestResponse(0);
// double br1 = d.bestResponse(1);
// System.out.println("BR0: " + br0);
// System.out.println("BR1: " + br1);
// System.out.println("Exploitability: " + Math.abs(pot - (br0 + br1)));
double[] r = d.trainVanilla(0, p1, p2);
double res = 0;
for (int i = 0; i < r.length; i++) {
res += 1.0 / r.length * r[i];
}
System.out.println("EV: " + res);
Save save = Save.createSave(d);
SimpleViewerDialog saveD = new SimpleViewerDialog(save);
saveD.setVisible(true);
running = false;
}
}
public static void generateTables() {
ObjectInputStream ois = null;
Object o = null;
try {
ois = new ObjectInputStream(Generator.class.getClassLoader().getResourceAsStream("handEvaluation/handRanks"));
o = ois.readObject();
if (o instanceof int[]) {
handRanks = (int[]) o;
}
}catch(EOFException e){
if (o instanceof int[]) {
handRanks = (int[]) o;
}
}
catch (Exception e) {
e.printStackTrace();
int card;
int handRank;
int keyIndex;
long key;
for (keyIndex = 0; keys[keyIndex] != 0 || keyIndex == 0; keyIndex++) {
for (card = 1; card < 53; card++) { // add a card to each
// previously calculated key
key = makeKey(keys[keyIndex], card); // create the new key
if (numCards < 7)
insertKey(key); // insert the new key into the key
// lookup table
}
}
for (keyIndex = 0; keys[keyIndex] != 0 || keyIndex == 0; keyIndex++) {
for (card = 1; card < 53; card++) {
key = makeKey(keys[keyIndex], card);
if (numCards < 7) {
handRank = insertKey(key) * 53 + 53; // if number of
// cards is < 7
// insert key
} else {
handRank = getHandRank(key); // if number of cards is 7
// insert hand rank
}
maxHandRankIndex = keyIndex * 53 + card + 53; // calculate
// hand rank
// insertion
// index
handRanks[maxHandRankIndex] = handRank; // populate hand
// rank lookup table
// with appropriate
// value
}
if (numCards == 6 || numCards == 7) {
// insert the hand rank into the hand rank lookup table
handRanks[keyIndex * 53 + 53] = getHandRank(keys[keyIndex]);
}
}
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(new FileOutputStream(
"src/handEvaluation/handRanks"));
oos.writeObject(handRanks);
} catch (FileNotFoundException f) {
// TODO Auto-generated catch block
f.printStackTrace();
} catch (IOException f) {
// TODO Auto-generated catch block
f.printStackTrace();
} finally {
if (oos != null)
try {
oos.close();
} catch (IOException g) {
// TODO Auto-generated catch block
g.printStackTrace();
}
}
} finally {
if (ois != null)
try {
ois.close();
} catch (IOException g) {
// TODO Auto-generated catch block
g.printStackTrace();
}
}
} // END generateTables method
答案 0 :(得分:0)
我找到了解决方案: 出现错误的原因是,当我通过控制台启动时,JVM分配了更多内存,而不是双击,即使我没有通过控制台传递任何参数。
我有一个OutOfMemoryException。我通过增加堆积来修复它。