我的 Greenfoot 程序作为一个 greenfoot 文件而不是一个 jar 文件

My Greenfoot Program works as a greenfoot file but not a jar file

我正在为学校制作一个充满词汇游戏的小街机。当我 运行 greenfoot window 中的程序时,它 运行 非常完美。但是当我制作它的 jar 文件时,它会在提示 Greenfoot.ask() 时停止。这是代码:

import greenfoot.*;
import java.util.*;
import java.io.*;
import java.lang.*;

public class Vocabulary 
{
   static ArrayList<World> back = new ArrayList<World>();
   static String vocab_List;
   static Scanner list =  null;
   static ArrayList<String> last = new ArrayList<String>();
   static Scanner all;
   static ArrayList<String> problems = new ArrayList<String>();
   static Map<String, String> answers = new HashMap<String, String>();
   static int x2 = 0;
   static int y = 1;
   static int count= 0;
   static boolean an;
   static World help;
   static int right = 0;

   public static boolean run() throws IOException
   {      
       right = 0;
       Collections.shuffle(problems);
      for(int x = 0; x < 3; x++)
      {
         String[] def = answers.get(problems.get(x)).split(" ");
         String answer = Greenfoot.ask("What does " + problems.get(x) + " mean?");
         count = 0;
         for(String temp: def)
         {
            if(answer.contains(temp))
               count++;
         }
         if(count > def.length/2 && count > 1 || count == def.length)
         {
            help.showText("Correct",300,100);
            Greenfoot.delay(50);
            right++;
         }
         else
         {
            help.showText("Actually... it means " + answers.get(problems.get(x)), 300, 100);
            Greenfoot.delay(50);
         }
         if(right >= 2)
         {
            an = true;
         }
         else
         {
             an = false;
         }
         try 
            {
            Thread.sleep(1000); 
         } 
         catch (InterruptedException e) 
         {
            e.printStackTrace();
         }      
         help.showText("",300,100);
      }
      return an;
   }

   public static boolean run(int num) throws IOException
   {      
      right = 0;
      Collections.shuffle(problems);
      for(int x = 0; x < num; x++)
      {
         String[] def = answers.get(problems.get(x)).split(" ");
         String answer = Greenfoot.ask("What does " + problems.get(x) + " mean?");
         count = 0;
         for(String temp: def)
         {
            if(answer.contains(temp))
               count++;
         }
         if(count > def.length/2 && count > 1 || count == def.length)
         {
            help.showText("Correct",300,100);
            Greenfoot.delay(50);
            right++;
         }
         else
         {
            help.showText("Actually... it means " + answers.get(problems.get(x)), 300, 100);
            Greenfoot.delay(50);
         }
         if(right >= num/2)
         {
            an = true;
         }
         else
         {
             an = false;
         }
         try 
            {
            Thread.sleep(1000); 
         } 
         catch (InterruptedException e) 
         {
            e.printStackTrace();
         }      
         help.showText("",300,200);
      }
      return an;
   }

   public static void setBack(World world)
   {
       back.add(world);
   }
   public static void setMode(ArrayList<Integer> lesson) throws IOException
   {
       problems.clear();
       answers.clear();
       x2 = 0;
       all = new Scanner(new File("All_Vocab.in"));
       for(int x : lesson)
       {
           list = new Scanner(new File("Vocab " + x + ".in"));
         while(all.hasNextLine())
         {
            last.add(all.nextLine() + "\n");
         }
         FileWriter fw = new FileWriter("All_Vocab.in");
            BufferedWriter bw = new BufferedWriter(fw);
         for(int c = 0; c < last.size(); c++)
         {
            bw.write(last.get(c));
         }
         bw.write(vocab_List+".in");
         bw.close();
         while(list.hasNextLine())
         {
             problems.add(list.nextLine());
             answers.put(problems.get(x2), list.nextLine());
             x2++;
         }
       }

   }

   public static void setHelp(World hell)
   {
       help = hell;
    }
}

如果您需要整个项目,请告诉我,我会分享。

没关系,问题是扫描仪没有读取文件,因为它找不到 jar.It 中的路径,在 Greenfoot.ask 暂停,因为在读取文件时,它抛出了一个IOException,使文件继续运行,最终导致 NullPointerException