我能够将程序编译成jar文件,它只有一个类。我不得不制作一个批处理文件,以便我可以运行jar而无需直接使用控制台。我在那里使用的代码是java -cp game.jar game
这允许我在运行批处理文件的计算机上运行程序。但是,当我将jar和批处理文件发送给朋友以便他可以运行它时,控制台就会闪烁。我让他安装了JRE,因为我猜这可能是问题,但它并没有解决它。我的程序代码是`
公共课程游戏{
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.out.println("+------------------------------------------------+");
System.out.println("|___ ___ ___ __ ___ __ |");
System.out.println("| | |__| |__ | |__ / _` |__ |\\ | | \\ |");
System.out.println("| | | | |___ |___ |___ \\__> |___ | \\| |__/ |");
System.out.println("| |");
System.out.println("|Made by Noah Baker |");
System.out.println("| *Pre-Alpha* |");
System.out.println("+------------------------------------------------+");
try {
Thread.sleep(5000);
} catch (InterruptedException ie) {
}
System.out.println("+------------------------------------------------+");
System.out.println("|There once was a fabled legendary item that if |");
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
}
System.out.println("|placed into the wrong hands could reek havoc. |");
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
System.out.println("|This item could destroy the very fabric of |");
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
}
System.out.println("|of space and time unless... |");
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
System.out.println("|unless... |");
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
}
System.out.println("Okay. I'm done with this.");
try {
Thread.sleep(2000);
}
catch (InterruptedException ie)
{
}
System.out.println("This \"game\" is nothing even close to one.");
try {
Thread.sleep(4000);
}
catch (InterruptedException ie)
{
}
System.out.println("Dana, you mean more to me than any game or thing could ever come close to.");
try {
Thread.sleep(3000);
}
catch (InterruptedException ie)
{
}
System.out.println("You are so absoulutely amazing and I am so incredibly lucky to be able to have");
System.out.println("had you as mine for the past 3 months.");
try {
Thread.sleep(5000);
}
catch (InterruptedException ie)
{
}
System.out.println("The past three months have been some of the greatest.");
try {
Thread.sleep(3000);
}
catch (InterruptedException ie)
{
}
System.out.println("I just have one question to ask you.");
try {
Thread.sleep(3000);
}
catch (InterruptedException ie)
{
}
System.out.println("Do you want to go to Homecoming with me?");
System.out.println(" ****** ******");
System.out.println(" ********** ********** ");
System.out.println(" ************* *************");
System.out.println("*****************************");
System.out.println("*****************************");
System.out.println("*****************************");
System.out.println(" ***************************");
System.out.println(" ***********************");
System.out.println(" *******************");
System.out.println(" *************** ");
System.out.println(" *********** ");
System.out.println(" ******* ");
System.out.println(" *** ");
System.out.println(" * ");
try {
Thread.sleep(6000);
}
catch (InterruptedException ie)
{
}
}
{
答案 0 :(得分:0)
让您的朋友在命令提示符下运行批处理文件。然后,他们应该能够查看(并可能发送给您)错误消息。
从朋友
收到错误讯息Exception in thread "main" java.lang.UnsupportedClassVersionError: game : Unsuported major.minor version 52.0 at
java.lang.ClassLoader.defineClass1(Native Method) at
java.lang.ClassLoader.defineClass(Unknown Source) at
java.security.SecureClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.access$100(Unknown Source)
<强>建议强>
你的朋友可能有旧版本的JRE。使用旧版本的Java编译代码。