从BlueJ创建Jar文件时如何处理“发生Java异常”问题

时间:2018-09-21 00:34:22

标签: java

整个夏天,我做了一个小型的文字游戏,但是直到大约两周前,它都没有制作.jar文件。它使用 Page Paragraph 这两个类从.txt文件中读取大量文本行。

我已经在BlueJ中反复运行主类(userMendacious),并且该类始终运行且没有错误。但是,当我尝试将整个项目(包含.txt文件,所有上述类以及一些无关的未使用的.txt文件)导出为.jar文件时,出现“发生Java异常”错误。这是我正在执行的类的代码:

import java.util.*;
import java.io.*;
public class userMendacious {
  public static void main (String[] args)
  throws FileNotFoundException{
    System.out.println ("Loading text...");
    File textLoader = new File("C:\\Users\\Gage.Desktop-PC\\Documents\\Finished Games\\userMendacious\\everyPage.txt");//File containing all game text in the form of Pages
    Scanner everyPage = new Scanner(textLoader);//Loads pages from everyPage.txt
    Scanner interactor = new Scanner (System.in);//Scanner for user input
    Scanner cheatHere = new Scanner (new File("cheatHere.txt"));
    Page screens[][] = new Page[4][4];//Array storing pages
    Boolean won = false;
    int x = 0;
    int y = 0;
    int[] height = new int[4];//stores previously-held y-values on each tab
    boolean[][] CRAPTCHASolved = new boolean[4][4];
    String[][] CRAPTCHASolutions = new String[4][4];//No cheating now (make code to fill this array with Strings representing CRAPTCHA solutions)
    String u = ("left");
    String v = ("forward");
    String s = ("right");
    String w = ("back");
    int failurepoints = 0;
    for (x = 0; x < 4; x++){
        for (y = 0; y < 4; y++){
        everyPage.nextLine();
        everyPage.nextLine();
        Paragraph a = new Paragraph (whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()));
        everyPage.nextLine();
        everyPage.nextLine();
        Paragraph b = new Paragraph (whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()));
        everyPage.nextLine();
        everyPage.nextLine();
        Paragraph c = new Paragraph (whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()));
        everyPage.nextLine();
        everyPage.nextLine();
        Paragraph d = new Paragraph (whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()));
        everyPage.nextLine();
        everyPage.nextLine();
        Paragraph e = new Paragraph (whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()), whitespaceRemoval(everyPage.nextLine()));
        Page z = new Page (a, b, c, d, e);
        screens[x][y] = z;
        CRAPTCHASolutions [x][y] = cheatHere.nextLine();
      }
    }
    x = 0;
    y = 0;
    while (won == false){//Procedure for gameplay
      formatPrint(screens[x][y].getA().toString());//causes exception right now because loop not set up
      System.out.println();
      formatPrint(screens[x][y].getB().toString());
      System.out.println();
      String t = interactor.nextLine();
      if (t.equalsIgnoreCase(u) && x > 0){//left command
        height[x] = y;
        x--;
        y = height[x];
        }
      if (t.equalsIgnoreCase(s) && x < 3){//right command   
          height[x] = y;
          x++;
          y = height[x];                                              }
      if (t.equalsIgnoreCase(v) == true && y < 3){//forward command/CRAPTCHAs
        formatPrint(screens[x][y].getC().toString());
        if (CRAPTCHASolutions[x][y].equalsIgnoreCase(interactor.nextLine())){//iff screens.equals [2][0] {system.out.println ("whataswellday")}
          if ((x == 3 && y == 2) == false && (x == 2 && y == 1) == false){
            formatPrint(screens[x][y].getE().toString());
            CRAPTCHASolved[x][y] = true;
            y++;  
          }else{
            formatPrint (screens[x][y].getD().toString()); 
            }
          }else{
          if (x == 2 && y == 1 || x == 3 && y == 2){
            formatPrint(screens[x][y].getE().toString());
            CRAPTCHASolved[x][y] = true;
            y++;
          }else{
            formatPrint(screens[x][y].getD().toString());   
            failurepoints++;
            }
                 }
                                                                                                          }
      if (t.equalsIgnoreCase(w) && y > 0){
        y--;   
                 }
          if (x == 0 && y == 3 && interactor.nextLine() == "37"){
        won = true;
        System.out.println ("Total number of wrong answers: " + failurepoints);
        System.out.println ("YOU WIN!");
        System.out.println ("THE END");
        System.out.println ("Thanks For Playing!");   
      }           
                                                                }                                                   
    }
  public static void formatPrint(String a){
    int v = 0;
    char t = '`';
    char u = '~';
    while (v < a.length()){
      char c = a.charAt(v);
      v++;
        if (c == u){
        System.out.println();
       }else{
        if (c == t){
          System.out.print (" ");
         }else{
          System.out.print (c);    
         }
      }
    }
    }
  public static String whitespaceRemoval (String s){
    String a = new String ("");
    Scanner b = new Scanner(s);
    while (b.hasNext()){
      a+= b.next();
      a+= ("`");
    }
    return a;
    }
}

对此感到奇怪的是,A。我知道这不是在BlueJ Terminal中发生的FileNotFoundException,B..jar文件同时导出并在相同版本的Java中运行,并且C.附加类,只有一种方法可以打印出预定的文本行,并且在导出时具有相同的问题。

0 个答案:

没有答案