Results 1 to 14 of 14
  1. #1
    mikaelafiery is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default I can compile my progam but I can't run it!

    Here is the code:

    Java Code:
    package me.mikaelafiery.TextBasedRPG;
    import java.util.Scanner;
    
    public class FirstGame {
    	public static void main(String[] args){
    		String Gamemode;
    		String axe;
    		String playername;
    		Scanner gmscanner = new Scanner(System.in);
    		Scanner axescanner = new Scanner(System.in);
    		Scanner namescan = new Scanner(System.in);
    		int notvalidcounter = 5;
    		int itemaxe = 0;
    		int health = 100;
    		
    		System.out.println("Welcome to Mika's first game!");
    		System.out.println("Which Gamemode would you like to choose?");
    		System.out.println("Type 'tutorial' to see how to play the game");
    		System.out.println("Or type 'start' if you already know how to play");
    		
    		Gamemode = gmscanner.nextLine();
    		if(Gamemode.equals("tutorial")){
    			System.out.println("There are various choices in the game");
    			System.out.println("If there are new choices you will be informed");
    			System.out.println("The choice 'ignore' is usually unneccesary but it sometimes");
    			System.out.println("Now to start the game just type 'start'");
    				Gamemode = gmscanner.nextLine();
    			}
    		if(Gamemode.equals("start")){
    				System.out.println("What's your name?");
    				playername = namescan.nextLine();
    			System.out.println("Health: " + health);
    			System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    			System.out.println("You see a pile of axes!");
    			System.out.println("Will you 'grab one' or 'ignore'?");
    			
    			axe = axescanner.nextLine();
    			if(axe.equals("grab one")){
    				itemaxe++;
    				System.out.println(playername + ": I'll probably need this...");
    			}else if(axe.equals("ignore")){
    				System.out.println("*You ignore the axes*");
    			}
    			
    			System.out.println("You see a village in the distance!");
    		}else{
    			System.out.println("That option is not valid!");
    			System.out.println("Goodbye");
    			}System.exit(0);
    		}
    	}

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: I can compile my progam but I can't run it!

    What do you mean you can't run it? How are you trying to run it? What happens when you try? Do you see an error message? If so, what?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    mikaelafiery is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    Quote Originally Posted by KevinWorkman View Post
    What do you mean you can't run it? How are you trying to run it? What happens when you try? Do you see an error message? If so, what?
    I used the Command Prompt!
    I did

    javac FirstGame.java

    then I did

    java FirstGame

    But it came up with this error:

    Exception in thread "main" java.lang.UnsupportedClassVersionError: FirstGame : U
    nsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: FirstGame. Program will exit.
    Last edited by mikaelafiery; 07-03-2012 at 06:57 PM.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: I can compile my progam but I can't run it!

    Did you google that error message?

    That's a result of compiling with a newer version of Java, like Java 7, but trying to run your code with an older version of Java, like Java 6.

    Check which version of javac (probably 7) and java (probably 6) you're using. You might have to look at your path specification.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    mikaelafiery is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    Quote Originally Posted by KevinWorkman View Post
    Did you google that error message?

    That's a result of compiling with a newer version of Java, like Java 7, but trying to run your code with an older version of Java, like Java 6.

    Check which version of javac (probably 7) and java (probably 6) you're using. You might have to look at your path specification.

    I do have jdk1.7.0_04 and jre7 but it still runs as jre6! I have two Program Files folders and one is called:
    Program Files
    and the other:
    Program Files(x86)

    I always use Program Files(x86) but it seems to be using jre6 from the other folder

    :'(
    Last edited by mikaelafiery; 07-03-2012 at 07:25 PM.

  6. #6
    mikaelafiery is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    This is really complicated stuff :'(

  7. #7
    b4viral is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    Quote Originally Posted by mikaelafiery View Post
    I do have jdk1.7.0_04 and jre7 but it still runs as jre6! I have two Program Files folders and one is called:
    Program Files
    and the other:
    Program Files(x86)

    I always use Program Files(x86) but it seems to be using jre6 from the other folder

    :'(
    i hope you are aware of class path, according to me it might be pointing to the older virsion of jre.
    you can check environment variables and set it to the bin directory of the latest jre.

  8. #8
    mikaelafiery is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    Quote Originally Posted by b4viral View Post
    i hope you are aware of class path, according to me it might be pointing to the older virsion of jre.
    you can check environment variables and set it to the bin directory of the latest jre.
    Okay, I've reinstalled the latest jre so I'll go check if the CLASSPATH is correct

  9. #9
    mikaelafiery is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    The classpath seems correct:

    .;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip

    but it still is running it on jre6 :/

  10. #10
    b4viral is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    Quote Originally Posted by mikaelafiery View Post
    The classpath seems correct:

    .;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip

    but it still is running it on jre6 :/
    it should be C:\Program Files (x86)\Java\jre7\bin as i said.

    FYI

    Classpath is path to executable files of your system, you can find java.exe in the above path.
    referring that your program will be executed.

    also please check if the referance to your old runtime environment is not there in classpath.

  11. #11
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: I can compile my progam but I can't run it!

    Classpath != path.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    b4viral is offline Member
    Join Date
    Jul 2012
    Posts
    17
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    Quote Originally Posted by KevinWorkman View Post
    Classpath != path.
    Hi mikaelafiery,

    regarding my above post, i am extreamly sorry, class path is the path where where your java .class files will be expected to be present.
    what i was talking about was PATH variable in system environment variables.

    Thanks Kevin for correcting me.


    -vj

  13. #13
    mikaelafiery is offline Member
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: I can compile my progam but I can't run it!

    Quote Originally Posted by b4viral View Post
    Hi mikaelafiery,

    regarding my above post, i am extreamly sorry, class path is the path where where your java .class files will be expected to be present.
    what i was talking about was PATH variable in system environment variables.

    Thanks Kevin for correcting me.


    -vj
    Ohh thankss!

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,809
    Rep Power
    19

    Default Re: I can compile my progam but I can't run it!

    Quote Originally Posted by mikaelafiery View Post
    The classpath seems correct:

    .;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip

    but it still is running it on jre6 :/
    Oooh I hate QuickTime for that...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. why won't this compile
    By joet1984 in forum Advanced Java
    Replies: 4
    Last Post: 08-31-2011, 09:50 AM
  2. What to do here(cant compile)?
    By Pojahn_M in forum New To Java
    Replies: 8
    Last Post: 08-06-2011, 01:55 AM
  3. would this compile?
    By stringkilla in forum New To Java
    Replies: 10
    Last Post: 10-24-2010, 03:27 PM
  4. Can't Compile
    By sidk47 in forum JavaServer Pages (JSP) and JSTL
    Replies: 7
    Last Post: 06-15-2010, 04:43 PM
  5. Not able to compile
    By bugger in forum New To Java
    Replies: 2
    Last Post: 01-09-2008, 10:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •