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 4 of 4

Thread: If statement not working

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default If statement not working

    I have an If statement and it seems that it is not functioning properly. The first part of the if statement is getting skipped over. I am checking to see if a ".lic" file exists and if it does then execute the command, otherwise give message that the file does not exist.



    try{
     
            String License = System.getProperty("user.dir") + ("*.lic");
            File license = new File(License);
              if (license.exists()){
            try{
            Runtime.getRuntime().exec(cmd);
     
            } catch (IOException ex) {
          }
              } else {
                  JOptionPane.showMessageDialog(null, "Need to activate license, please see README file");
              }
          }catch(HeadlessException e){
              // if any error occurs
     
          }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: If statement not working

    first part of the if statement is getting skipped over.
    Do you mean the else part is being executed?
    Or do you mean that the exec method is not doing what you want?

    Note: I see an empty catch block. Add a call to the printStackTrace method inside the catch block to show if there are any execution errors/
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: If statement not working

    Still, need help on this.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: If statement not working

    You need to see what the problem is. Is the if statement executing the true part? It must be if the else part is not showing JOptionPane message.
    To see: add a print statement inside the if statement to show that it is executing.
    Also Add a call to the printStackTrace method inside the catch block to show if there are any execution errors.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. if-else statement not working and dont know why
    By HappyCamper in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 14th, 2014, 11:27 PM
  2. [SOLVED] If Statement not working
    By Szpak in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 5th, 2014, 05:37 PM
  3. If else statement not working.
    By DarkestLord in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 13th, 2014, 01:17 PM
  4. if else if elese if.... statement not working
    By ahans in forum Loops & Control Statements
    Replies: 4
    Last Post: October 25th, 2013, 01:54 PM
  5. Replies: 2
    Last Post: June 25th, 2013, 06:33 AM