Results 1 to 5 of 5
  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default IF Else Value Printing Error

    Java Code:
    jb.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent ae){
    				 String s=jt.getText();
    				String s1=cabnT.getText();
    				String time=timT.getText();
                    int b=24;
                    String t_finl="h";
                    String err="error";
                    String hr="Hr";
                    String min="Min";
    				jt.setText(" ");
                    cabnT.setText(" ");
                    timT.setText(" ");				
    				
                      if(time.equals(b))
                     {
                       t_finl=hr;
                     }
                     else
                     {
                        t_finl=min; 
                       }
                       try{
    					
    					FileWriter fw=new FileWriter("C://Cafe Box//"+(date)+".txt",true);
    	 
                    	 BufferedWriter bf=new BufferedWriter(fw);
    	                 bf.newLine();
    	                 bf.write(s);
    					 bf.newLine();
    					 bf.write(s1);
                         bf.newLine();
                         bf.write(time+t_finl);
                         bf.newLine();
                         bf.write("----------------------");
                         bf.newLine();					 
    	                 bf.close();
    
    				}
    				catch(IOException io){}
    				
    			}
    this code is only takes "else" value it skips the "if" if i enter 24 or any value it prints only "Min"..

    How to Fix?

    Thanks...

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: IF Else Value Printing Error

    Apparently time does not equal b. Only you know why not.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: IF Else Value Printing Error

    Look when i enter 24 it doest not get it and not print "Hr."

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: IF Else Value Printing Error

    You are comparing a String to an int. That will always be false, no matter what you put in there. Make sure to compare Strings with Strings and int with int.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: IF Else Value Printing Error

    yeaahh....Problem so;ved
    thanks...

Similar Threads

  1. Replies: 8
    Last Post: 07-26-2013, 07:04 PM
  2. Replies: 1
    Last Post: 07-26-2013, 05:14 PM
  3. Error while printing out arrays
    By cjgarcia in forum New To Java
    Replies: 1
    Last Post: 05-03-2012, 12:34 AM
  4. Error printing from Read in file.
    By Accendo in forum New To Java
    Replies: 6
    Last Post: 01-21-2011, 06:07 AM
  5. Printing 2D Array Error
    By noble in forum New To Java
    Replies: 9
    Last Post: 11-09-2010, 05:31 PM

Tags for this Thread

Posting Permissions

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