分叉的Java VM异常退出. JUnit测试? [英] Forked Java VM exited abnormally. JUnit Test?

查看:91
本文介绍了分叉的Java VM异常退出. JUnit测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Java程序,在将其上传到学校的评分系统"WebCat"之前,它似乎运行良好,我假设它只是在运行JUnit.它返回的错误是:

I have a simple Java program that seems to work well until uploaded to my school's grading system, "WebCat", which I'm assuming is just running JUnit. The error it kicks back is:

分叉的Java VM异常退出.请注意,报告中的时间不会反映> VM退出之前的时间.

Forked Java VM exited abnormally. Please note the time in the report does not reflect the >time until the VM exit.

我已经研究了此问题,并且故障排除的主要第一步似乎是查看转储日志.不幸的是,在这种情况下,我无法做到这一点.考虑到缺少评分系统的反馈以及缺少编译或运行时错误,我真的对如何开始解决此问题感到困惑.

I've researched this issue and and the main first troubleshooting step seems to be to look at the dump log. Unfortunately I cannot do that in this case. I am really at a loss on how to begin to troubleshoot this considering the lack of feedback from the grading system and the lack of compile or run-time errors.

如果有人熟悉此错误,或者至少可以为我提供一些从哪里开始进行故障排除的指导,请使用以下代码.非常感谢!

Here is the code if anyone is familiar with this error or can at least give me some direction of where to begin troubleshooting. Much appreciated!

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.io.IOException;



class PlayerApp {
    public static void showMenu()
    {
        System.out.println("Player App Menu");
        System.out.println("P - Print Report");
        System.out.println("A - Add Score");
        System.out.println("D - Delete Score");
        System.out.println("L - Find Lowest Score");
        System.out.println("H - Find Highest Score");
        System.out.println("Q - Quit");
    }
    public static void main(String[] args) throws IOException 
    {   
        if (args.length == 0)
        {
            System.out.println("File name was expected as a run argument.");
            System.out.println("Program ending.");
            System.exit(0);
        }
        String fileName = args[0];
        Scanner sc = new Scanner(System.in);
        String stnew = "";
        boolean exit = false;
        Player p = null;
        double[] scoreList;

        File dbFile = new File(fileName);
        FileInputStream fis = new FileInputStream(fileName); 
        InputStreamReader inStream = new InputStreamReader(fis); 
        BufferedReader stdin = new BufferedReader(inStream);
       String name = stdin.readLine();
       stnew = stdin.readLine();
       int numScore = Integer.parseInt(stnew);
       scoreList = new double[numScore];
       for (int i = 0; i < numScore; i++)
       {
          stnew = stdin.readLine();
          scoreList[i] = Double.parseDouble(stnew);
       }

       p = new Player(name, numScore, scoreList);

       stdin.close();

        System.out.println("File read in and Player object created.");
       showMenu();
       while (exit == false)
       {

        System.out.print("\nEnter Code [P, A, D, L, H, or Q]:");
        String choice = sc.nextLine().toLowerCase();
        if (choice.equals("p"))
        {
            System.out.println(p.toString());
        }
        else if (choice.equals("a"))
        {
            System.out.print("   Score to add: ");
            stnew = sc.nextLine();
            double scoreIn = Double.parseDouble(stnew);
            p.addScore(scoreIn);
        }
        else if (choice.equals("d"))
        {
            System.out.print("   Score to delete: ");
            stnew = sc.nextLine();
            double scoreIn = Double.parseDouble(stnew);
            p.deleteScore(scoreIn);
            System.out.println("   Score removed.");
        }
        else if (choice.equals("l"))
        {
            System.out.println("   Lowest score: " + p.findLowestScore());
        }
        else if (choice.equals("h"))
        {
            System.out.println("   Highest score: " + p.findHighestScore());
        }
        else if (choice.equals("q"))
        {
            exit = true;
        }
        }


   }
}

休息

import java.text.DecimalFormat;



public class Player {

    //Variables
    private String name;
    private int numOfScores;
    private double[] scores = new double[numOfScores];

    //Constructor
    public Player(String nameIn, int numOfScoresIn, double[] scoresIn) {
       name = nameIn;
       numOfScores = numOfScoresIn;
       scores = scoresIn;
   }

    //Methods
    public String getName() {
       return name;
    }
    public double[] getScores() {
       return scores;
    }
    public int getNumScores() {
       return numOfScores;
    }
    public String toString() {

        String res = "";
        DecimalFormat twoDForm = new DecimalFormat("#,###.0#");
      DecimalFormat twoEForm = new DecimalFormat("0.0");
        res += "   Player Name: " + name + "\n   Scores: ";
        for (int i = 0; i < numOfScores; i++)
        {
            res += twoDForm.format(scores[i]) + " ";
        }
        res += "\n   Average Score: ";
        res += twoEForm.format(this.computeAvgScore());
        return res;
    }
    public void addScore(double scoreIn) {
       double newScores[] = new double[numOfScores +1 ];
       for (int i = 0; i < numOfScores; i++)
       {
           newScores[i] = scores[i];
       }
       scores = new double[numOfScores + 1];
       for(int i = 0; i < numOfScores; i++)
       {
           scores[i] = newScores[i];
       }
       scores[numOfScores] = scoreIn;
       numOfScores++;
    }
    public boolean deleteScore(double scoreIn) {
        boolean found = false; 
        int index = 0;
        for (int i = 0; i < numOfScores; i++)
        {
           if (scores[i] == scoreIn)
            {
                found = true;
                index = i;
            }
        }
        if (found == true)
        {
            double newScores[] = new double[numOfScores -1 ];
            for (int i = 0; i < index; i++)
            {
               newScores[i] = scores[i];
            }
            for (int i = index + 1; i < numOfScores; i++)
            {
                newScores[i - 1] = scores[i];
            }
            scores = new double[numOfScores - 1];
            numOfScores--;
            for (int i = 0; i < numOfScores; i++)
            {
                scores[i] = newScores[i];
            }
            return true;
        }
        else
        {
            return false;
        }


    }
    public void increaseScoresCapacity() 
    {
        scores = new double[numOfScores + 1];
        numOfScores++;
    }
    public double findLowestScore() {
        double res = 100.0;
        for (int i = 0; i < numOfScores; i++)
        {
            if (scores[i] < res)
            {
                res = scores[i];
            }
        }
        return res;
    }
    public double findHighestScore() {
        double res = 0.0;
        for (int i = 0; i < numOfScores; i++)
        {
            if (scores[i] > res)
            {
                res = scores[i];
            }
        }
        return res;
    }
    public double computeAvgScore() {
        double res = 0.0;
      if (numOfScores > 0) {
           for (int i = 0; i < numOfScores; i++)
        {
               res += scores[i];
           }
           return res / (double)(numOfScores);
      }
      else {
         //res = 0.0;
         return res;
      }
    }

}

推荐答案

您的程序正在调用System.exit(0)进行某些输入.不要那样做!这正是该消息告诉您的:JVM在文本的中间退出,而评分代码尚未完成.不用调用exit(),只需使用return尽早从main()返回即可.

Your program is calling System.exit(0) for certain inputs. Don't do that! That's exactly what the message is telling you: that the JVM exited in the middle of the text, before the scoring code could finish up. Instead of calling exit(), just use return to return from main() early.

这篇关于分叉的Java VM异常退出. JUnit测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆