Results 1 to 9 of 9
  1. #1
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default .Jar file wont open but works fine if i run it through CMD No Error Messages!

    Hey guys!

    Right another problem I've made a simple Rock Paper Scissors game which works absolutely fine! It has compiled with no errors, and runs fine if u open it with CMD (java -jar filename.jar)

    The problem I'm having is when I double click it I get a little loading icon on the mouse, but it doesn't do anything.. Why would it run in CMD and not when I double click the file?

    I'm using JOptionPane to show the dialog's.

    Here is my code if needs be:

    Java Code:
    package main;
    
    
    import javax.swing.*;
    
    public class RockPaperScissors {
    
    	public static void main(String[] args) {
    		
    		
    		//ask the user if they want to play. 
    		int play = JOptionPane.showConfirmDialog(null, "Welcome to Rock Paper Scissors!\n would like to play?");
    		
    		if (play == JOptionPane.YES_OPTION) 
    		{
    			
    			
    			//Ask user to choose either Rock Paper Scissors.
    		    String decision = JOptionPane.showInputDialog(null, "Good Decision! Choose 0 for Rock, 1 for Paper or 2 for Scissors!");
    			
    			int answer = Integer.parseInt(decision);
    		    
    			//Convert decision to Rock/Paper/Scissors 
    			String decisionRPS = "answer";
    			
    			if (answer == 0){
    				decisionRPS = "Rock";
    				
    			}
    			if (answer == 1){
    				decisionRPS = "Paper";
    				
    			}
    			if (answer == 2){
    				decisionRPS = "Scissors";
    				
    			}
    			
    			JOptionPane.showMessageDialog(null, "You chose:  " + decisionRPS);
    			
    			//Work out what computer chose  
    			double computerChoice;
    			computerChoice = Math.random() * 2;
    			
    			//convert Random number into INT 
    			int compChoice = (int)computerChoice;
    			
    			String cDecisionRPS = "answer";
    			
    			if (compChoice == 0){
    				cDecisionRPS = "Rock";
    				
    			}
    			if (compChoice == 1){
    				cDecisionRPS = "Paper";
    				
    			}
    			if (compChoice == 2){
    				cDecisionRPS = "Scissors";
    				
    			}
    			
    			JOptionPane.showMessageDialog(null, "The computer chose: " + cDecisionRPS);
    			
    			//Work out who won rock > scissors , scissors > paper, paper > rock
    			
    			//Draws
    			 if(compChoice == 0 && answer == 0)
    			{
    				JOptionPane.showMessageDialog(null, "Draw! Nobody wins you both chose Rock ");
    			
    			}
    			 if(compChoice == 1 && answer == 1)
    			{
    				JOptionPane.showMessageDialog(null, "Draw! Nobody wins you both chose Paper ");
    			
    			}
    			 if(compChoice == 2 && answer == 2)
    			{
    				JOptionPane.showMessageDialog(null, "Draw! Nobody wins you both chose Scissors ");
    			
    			}
    			 
    			 //User Wins
    			 if(compChoice == 0 && answer == 1)
    			{
    				JOptionPane.showMessageDialog(null, "Well Done! You Chose Paper and Win!  ");
    			
    			}
    			 if(compChoice == 1 && answer == 2)
    			{
    				JOptionPane.showMessageDialog(null, "Well Done! You Chose Scissors and Win! ");
    			
    			}
    			 if(compChoice == 2 && answer == 0)
    			{
    				JOptionPane.showMessageDialog(null, "Well Done! You Chose Rock and Win! ");
    			
    			}
    			 
    			 //User Loses
    			 if(compChoice == 1 && answer == 0)
    			{
    				JOptionPane.showMessageDialog(null, "Unlucky! You chose Rock and Lost! ");
    			
    			}
    			 if(compChoice == 0 && answer == 2)
    			{
    				JOptionPane.showMessageDialog(null, "Unlucky! You chose Scissors and lost! ");
    			
    			}
    			 if(compChoice == 2 && answer == 1)
    			{
    				JOptionPane.showMessageDialog(null, "Unlucky! You chose Paper and lost! ");
    			
    			}
    
    			
    		}
    		else
    		{
    			System.exit(0);
    		}
    		
    		
    		
    		
    	}
    
    }
    Thanks in advanced

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: .Jar file wont open but works fine if i run it through CMD No Error Messages!

    You have to associate the jar file with JRE in your system.

  3. #3
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: .Jar file wont open but works fine if i run it through CMD No Error Messages!

    Quote Originally Posted by Eranga View Post
    You have to associate the jar file with JRE in your system.
    Thanks, I have other Java programs which run fine, If they run fine, then surely my file should too?

    My Manifest file is as follows (if it helps)
    Manifest-Version: 1.0
    Class-Path: .
    Main-Class: main.RockPaperScissors

    Regards

  4. #4
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: .Jar file wont open but works fine if i run it through CMD No Error Messages!



    Uploaded with ImageShack.us

    My association.. I believe that is correct??

    Regards

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: .Jar file wont open but works fine if i run it through CMD No Error Messages!

    Right-click on the file and see that specific jar file also attach with the same. In properties you can find that.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default Re: .Jar file wont open but works fine if i run it through CMD No Error Messages!

    have other Java programs which run fine,
    Are you saying that you have some .jar files that work and some that do not work?
    What is the difference between the two?

    Are there different versions of java involved?
    What version created the jar files that work and what version created the ones that don't work?
    What version of the java.exe command is associated with the jar file by the OS?

  7. #7
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: .Jar file wont open but works fine if i run it through CMD No Error Messages!

    Yup it is attached with exactly the same as the associations..

  8. #8
    DiciWales is offline Member
    Join Date
    Mar 2012
    Posts
    22
    Rep Power
    0

    Default Re: .Jar file wont open but works fine if i run it through CMD No Error Messages!

    Ok Ok, thanks norm!

    I was creating projects in JavaSE -1.7 Where I only had JavaSE -1.6 installed.

    It works absolutely fine now!!

    Thanks for your help both of you!!

    Kind Regards

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 3
    Last Post: 10-29-2011, 01:39 AM
  2. Replies: 1
    Last Post: 11-03-2010, 09:49 AM
  3. Programming Issues, JForm second window wont open.
    By DarkJ3JB in forum New To Java
    Replies: 1
    Last Post: 04-16-2010, 02:23 PM
  4. Error during file open
    By helloamitk@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 10-14-2008, 03:26 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
  •