1

I was able to compile a program into a jar file, it only has one class. I had to make a batch file so that I could run the jar without having to use the console directly. The code i used there was java -cp game.jar game This allowed me to run the program on my computer with running the batch file. But, when i send the jar and batch file to a friend so he could run it, the console just flashes. I made him install a JRE because I guessed that could have been the problem, but it didn't fix it. My program code is `

public class game {

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) 
        {
        }
    }
{
Noah Baker
  • 31
  • 4

1 Answers1

0

Ask your friend to run the batch file from within a command prompt. They should then be able to view (and possibly send you) the error message.

Error message received from friend

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)

Advice

Your friend probably has an older version of the JRE. Compile your code with an older version of Java.

Jason
  • 11,744
  • 3
  • 42
  • 46
  • Exception in thread "main" java.lang.UnsupportedClassVersionError: game : Unsup orted 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) – Noah Baker Sep 02 '15 at 00:38
  • at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) – Noah Baker Sep 02 '15 at 00:39
  • 3
    Looks like you compiled the application with a higher version of Java than the JRE that your friend has. – Jason Sep 02 '15 at 00:39
  • That was the error that my friend got. I'm guessing i need to take the exception and throw it, right? – Noah Baker Sep 02 '15 at 00:40
  • 3
    Either ask your friend to install a newer version of the JRE, or compile your code with an older version of Java. See the following which is a similar problem: http://stackoverflow.com/questions/10382929/how-to-fix-unsupported-major-minor-version-51-0-error – Jason Sep 02 '15 at 00:54
  • I would recommend to compile it in some old version as @Jason mentions. You can't be sure if the person you want to send it to has the most recent JRE. – Manik Sep 02 '15 at 01:18