Results 1 to 4 of 4
  1. #1
    nour is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default if statment not working good

    i have a problem with if statement,
    if i wright down more than 2 if statement's , i get an application that doesn't
    work with no errors just it's not working here is the code:

    import java.util.Calendar;
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.Toast;


    public class Awkat_sala_lodActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Calendar ci = Calendar.getInstance();

    String CiDateTime =
    (ci.get(Calendar.MONTH) + 1) + "/" +
    ci.get(Calendar.DAY_OF_MONTH) + " " +
    ci.get(Calendar.HOUR) + ":" +
    ci.get(Calendar.MINUTE);


    if(ci.get(Calendar.MONTH) + 1 == 3) {
    if(ci.get(Calendar.DAY_OF_MONTH) == 24 && ci.get(Calendar.HOUR)==18){
    Toast.makeText(Awkat_sala_lodActivity.this, "test", Toast.LENGTH_LONG).show();
    }
    }
    }
    }


    but if i erase the half if statement ( && ci.get(Calendar.HOUR)==18 ) it works :


    public class Awkat_sala_lodActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Calendar ci = Calendar.getInstance();

    String CiDateTime =
    (ci.get(Calendar.MONTH) + 1) + "/" +
    ci.get(Calendar.DAY_OF_MONTH) + " " +
    ci.get(Calendar.HOUR) + ":" +
    ci.get(Calendar.MINUTE);


    if(ci.get(Calendar.MONTH) + 1 == 3) {

    Toast.makeText(Awkat_sala_lodActivity.this, "test", Toast.LENGTH_LONG).show();
    }
    }
    }

    why i have this error , and how can i solve it
    thanks for the helpers.
    Last edited by nour; 03-25-2012 at 08:16 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: if statment not working good

    Try toasting ci.get(Calendar.MONTH), ci.get(Calendar.DAY_OF_MONTH) and ci.get(Calendar.HOUR) before the if statements to make sure they have the values you think they have.

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: if statment not working good

    Isn't it because today is not 24 and it isn't 18 o'clock?

  4. #4
    nour is offline Member
    Join Date
    Oct 2011
    Posts
    12
    Rep Power
    0

    Default Re: if statment not working good

    ok
    i found a solution
    Last edited by nour; 03-25-2012 at 11:31 PM.

Similar Threads

  1. Missing Return Statment, HELP PLEASE.
    By dburgess in forum New To Java
    Replies: 2
    Last Post: 06-05-2011, 07:40 PM
  2. If statment not working:(
    By Harris68 in forum Networking
    Replies: 6
    Last Post: 02-24-2010, 10:41 PM
  3. Hello Good Morning, Good afternoon, and Good Evening
    By MrFreeweed in forum Introductions
    Replies: 3
    Last Post: 12-11-2009, 03:32 PM
  4. statment replay!!!
    By moamen in forum New To Java
    Replies: 4
    Last Post: 09-25-2009, 12:49 PM
  5. Issue using FOR statment with NetBeans
    By Deathmonger in forum Advanced Java
    Replies: 3
    Last Post: 07-30-2008, 12:46 AM

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
  •