Java 当jar通过控制台启动时,GUI应用程序运行良好,但若jar通过双击启动,则会出现错误

Java 当jar通过控制台启动时,GUI应用程序运行良好,但若jar通过双击启动,则会出现错误,java,Java,我有一个GUI应用程序,当通过控制台启动时,它运行良好。如果我通过双击启动jar,它会很好地启动,但在某个时刻,当从jar读取序列化对象时,它可能会停止 有关守则: public static void nashEQ() { if(!running){ running = true; Generator.generateTables(); int u0 = Generator.handRanks[53 + Board[0]]; int u1 = Gener

我有一个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
publicstaticvoidnasheq(){
如果(!正在运行){
运行=真;
Generator.generateTables();
int u0=生成器.手列[53+板[0];
int u1=生成器.手列[u0+板[1]];
int u2=生成器.手列[u1+板[2];
int u3=生成器.手列[u2+板[3];
int u4=生成器.手列[u3+板[4];
分布一。集合概率();
分布两个集合概率();
distributionOne.集合相对概率(distributionTwo);
分配2.集合相对概率(分配单);
分配1.设置等级(u4);
分配两个等级(u4);
DecisionNode d=createGame();
double[]p1=distributionOne.getProbabilities();
double[]p2=distributiontw.getProbabilities();
对于(int i=0;i我找到了解决方案:
错误的原因是,当我通过控制台启动JVM时,JVM分配的内存比双击要多,即使我没有通过控制台传递任何参数


我有一个OutOfMemoryException。我通过增加heapsize来修复它。

当你说它停止时,你会得到一个stacktrace,对吗?你能发布一个吗?这个
“src/handEvaluation/handRanks”
对我来说似乎是错误的。您不太可能在运行时访问
src
目录。可能的原因是程序执行上下文(运行它的目录)控制台和双击时的控制台不同…我通过双击打开jar时,不会得到任何控制台输出或stacktrace,即使我事先打开了控制台。我使用src/…的部分不会执行。它只会在没有创建handRanks文件的情况下执行,所以不应该是问题。我检查了路径当我通过控制台打开它并双击它的两个文件时:/C:/CFRM.jar!/handEvaluation/handRanks.1)为了更快地获得更好的帮助,发布一个.2)更改代码的形式
catch(Exception e){..
catch(Exception e){e.printStackTrace();//非常有用!。
3)请学习常见的(特别是用于名称的大小写)对于类、方法和属性名称,并一致使用它们。4)对代码块使用一致的逻辑缩进。代码缩进旨在帮助人们理解程序流程。