Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: error when running with jar

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default error when running with jar

    hi.. i am preparing my codes for submission so i package my code into jar file.. but upon running the codes using the jar, there seems to be an error with my code.. the timer action performed method seems to be running only 1 time..

    timer action performed method
     class btRec implements ActionListener
        {
     
            public void actionPerformed(ActionEvent e)
            {
               System.out.println("timer repaint");
                repaint();
            }
        }

    paint method
    public void paint(Graphics g) {
        	super.paint(g);
        	hangman(g,wrong);
        	System.out.println("Timer status: "+t1.isRunning());
        	if(firstRun)
        	{
        		firstRun=false;
     
        		btPlay.sendMessage("play");
     
        	}
    String msg = btPlay.readMessage();
     
        	//System.out.println("paint: "+msg);
        	if (msg!=null)
        	{
    ....
    }

    when the firstRun was true... the timer isRunning return true
    the code also utilise JFrame and some JButtons... the JButtons does not seems to come out tooo

    this error does not seems to happen when using the ecplise Run As> Java Application


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: error when running with jar

    If there is an error message, post the full text of the message here.
    Where is the code showing the initialization of the timer?
    Where is the code showing the timer start?
    Where is any other code accessing or modifying the timer?

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error when running with jar

    Quote Originally Posted by jps View Post
    If there is an error message, post the full text of the message here.
    Where is the code showing the initialization of the timer?
    Where is the code showing the timer start?
    Where is any other code accessing or modifying the timer?
    no error message is being displayed...
    initialization and starting of timer in constructor...
    public C_Play(String st, Bluetooth newBT){
    		name = st;
    		btPlay=newBT;
    		gui(st);	
    		t1= new Timer(100,new btRec());
    		t1.start();
    	}
    the timer is not being modify once started

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: error when running with jar

    In that case I would say it is time to add some printlns to find out where things do not happen as expected. Verify the timer is running and repeats is set to true.
    If you still can not figure it out post more of the code where we can see what is happening.

  5. #5
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error when running with jar

    Output:
    BTSend Log.listener: Using Bluetooth device with address = 00165316F6AD
    BlueCove version 2.1.0 on winsock
    BTSend Log.listener: Connected to null
    Sending msg: play
     
    Timer status: true
    Timer repeat: true
    BlueCove stack shutdown completed

    Codes:
    Timer t1= new Timer(100,new btRec());
     
    		t1.start();
     
     
      class btRec implements ActionListener // timer actionListener
        {
     
            public void actionPerformed(ActionEvent e)
            {
               System.out.println("timer repaint");
                repaint();
            }
        }
     
    public void paint(Graphics g) {
        	super.paint(g);
        	hangman(g,wrong);
     
        	if(firstRun)
        	{
        		firstRun=false;
     
        		btPlay.sendMessage("play");
     
        	}
        	System.out.println("Timer status: "+t1.isRunning());
        	System.out.println("Timer repeat: "+t1.isRepeats());
        	//System.out.println("In paint for "+wrong);
        	String msg = btPlay.readMessage();
     
        	System.out.println("paint: "+msg);
        	if (msg!=null)
        	{
     
     
        		if (msg.equalsIgnoreCase("wrong"))
        		{
     
        			JOptionPane.showMessageDialog(null, "The letter "+lastPressed+" is wrong.Please input next letter or solve the puzzle.");
        			if (wrong<7)
        			wrong++;
        			life--;
        			statusScore.setText("Life: "+life);
        			if(wrong==7)
        			{
        				btPlay.sendMessage("-3");
        				//msg="lose";
        			}
        			hangman(g,wrong);
        		}
        		else if(msg.startsWith("done"))
        		{
        			realWord=msg.substring(msg.indexOf(":")+1, msg.length());
        			System.out.println("Word is: "+realWord);
        			JOptionPane.showMessageDialog(null, "Ready to go!!");
        			for(int i=0;i<b.length;i++)
        			{
        				b[i].setEnabled(true);
        			}
        			msg="";
        		}
        		else if(msg.equalsIgnoreCase("correct"))
        		{
        			intScore++;
        			//request next option
        			if (intScore!=realWord.length())
        			JOptionPane.showMessageDialog(null, "The letter "+lastPressed+" is correct.Please input next letter or solve the puzzle.");
        			System.out.println("intScre= "+intScore);
        			System.out.println("rWord= "+realWord.length());
     
     
        		}
        		if (msg.equals("win"))
        		{
     
        			msg="";
        			winLose=true;
        			//token=new StringTokenizer(msg,"win");
        			//word.setText(token.nextToken().toUpperCase());
        			D_Win win = new D_Win(this,btPlay);
        			//setVisible(false);
        		}
        		else if (msg.equals("lose"))
        		{
     
        			msg="";
        			winLose=true;
        			E_Lose lose = new E_Lose(this,btPlay,realWord);
        			//setVisible(false);
        		}
        		if(winLose==false)
        		{
     
        			//System.out.println("?????????");
        			btPlay.sendMessage("-2");
        		}
     
     
        	}
     
     
        }

    as seen from the output, the program seems to be stucked at the println for "Timer repeat: true"..

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: error when running with jar

    The custom painting tutorial might help

  7. #7
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error when running with jar

    Quote Originally Posted by jps View Post
    sorry if this question is a bit noob.. the tutorial only show like a class involved.. based on the product structure..

    when the program 1st run, Main.java, the only class with main method, would run and call the A_User.java for user to input his/her name and after the user press enter it will invoke B_Connect.java which is to start the Bluetooth transmission. then the C_Play.java will be invoke which is the class that has the errors as mention in the opening thread...

    Project structure:
    projectstruc.jpg

    Project codes

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: error when running with jar

    Please post all related code/images on the forum. There is no guarantee third party sites will continue to host content over time

    Looking at all of the logic inside a paint method, my best suggestion is to actually read the tutorial and the swing turorials.
    Changing a little code to fix the "timer problem" will not fix the code. My suggestion to fix the code is to start with all of the logic outside the paint method. Fully explained in the tutorials.

  9. #9
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error when running with jar

    i just found out that the println statement only print the 2 println i added at paint component.. the one at the timer actionperformed method isn't being printed... thought the sequence of the program is to do the println first before calling repaint().

    timer actionperformed:

    class btRec implements ActionListener
        {
     
            public void actionPerformed(ActionEvent e)
            {
               System.out.println("timer repaint");
                repaint();
            }
        }
    paint method:

     public void paint(Graphics g) {
        	super.paint(g);
        	hangman(g,wrong);
     
        	if(firstRun)
        	{
        		firstRun=false;
     
        		btPlay.sendMessage("play");
     
        	}
        	System.out.println("Timer status: "+t1.isRunning());
        	System.out.println("Timer repeat: "+t1.isRepeats());
    .....

    command prompt output of jar program:

    C:\Users\Ben\Dropbox\presentation\demo>java -jar Hangman.jar
    BTSend Log.listener: Using Bluetooth device with address = 00165316F6AD
    BlueCove version 2.1.0 on winsock
    BTSend Log.listener: Connected to null
    Sending msg: play
     
    Timer status: true
    Timer repeat: true
    BlueCove stack shutdown completed

    so now i am not sure if it is the timer error of paint component error... tried the tutorial provided but the error still exist...

Similar Threads

  1. Running .JAR file issue.
    By JosPhantasmE in forum What's Wrong With My Code?
    Replies: 12
    Last Post: January 27th, 2013, 07:07 AM
  2. Problem running .jar in Windows 7
    By SpiceProgrammer in forum Java Theory & Questions
    Replies: 3
    Last Post: December 21st, 2011, 01:28 AM
  3. Running an Applet With JAR file
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 20th, 2011, 07:10 AM
  4. [SOLVED] jar file Built(clean and build) perfectly, but not running as jar
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: July 11th, 2011, 11:41 AM
  5. Authentication system for running/downloading a .jar
    By KiwiProg in forum Java Theory & Questions
    Replies: 1
    Last Post: January 3rd, 2011, 01:29 AM