Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Android Day of Week Calculator

Android Day of Week Calculator

Scheduled Pinned Locked Moved Android
androidquestion
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David Crow

    Seriously? A NullPointerException is being thrown on line 230 because date is null. A simple walkthrough with the debugger would have revealed this. :doh:

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

    P Offline
    P Offline
    Pavlex4
    wrote on last edited by
    #3

    I have initialized Date date = new Date(); but now I get application has stopped working and error is still in the same line!!!

    try
    {
    Date date = new Date();
    String getdate = spinner.getItemAtPosition(position).toString() + value
    + textView2.getText().toString();
    date = sdf.parse(getdate);
    } catch (ParseException ex)
    {
    // handle parsing exception if date string was different from the pattern applying into the SimpleDateFormat contructor
    }
    // isDateValid function call
    isValid = isDateValid(date.getMonth(), date.getDay(), date.getYear());

    D 1 Reply Last reply
    0
    • P Pavlex4

      I have initialized Date date = new Date(); but now I get application has stopped working and error is still in the same line!!!

      try
      {
      Date date = new Date();
      String getdate = spinner.getItemAtPosition(position).toString() + value
      + textView2.getText().toString();
      date = sdf.parse(getdate);
      } catch (ParseException ex)
      {
      // handle parsing exception if date string was different from the pattern applying into the SimpleDateFormat contructor
      }
      // isDateValid function call
      isValid = isDateValid(date.getMonth(), date.getDay(), date.getYear());

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #4

      Pavlex4 wrote:

      I have initialized Date date = new Date();

      Which is not the one being passed to isDateValid().

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      P 1 Reply Last reply
      0
      • D David Crow

        Pavlex4 wrote:

        I have initialized Date date = new Date();

        Which is not the one being passed to isDateValid().

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        P Offline
        P Offline
        Pavlex4
        wrote on last edited by
        #5

        So,what should I do?

        D 1 Reply Last reply
        0
        • P Pavlex4

          So,what should I do?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #6

          Maybe look at (or around) line 12.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          P 1 Reply Last reply
          0
          • D David Crow

            Maybe look at (or around) line 12.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            P Offline
            P Offline
            Pavlex4
            wrote on last edited by
            #7

            You mean this "private Date date;" ?

            D 1 Reply Last reply
            0
            • P Pavlex4

              You mean this "private Date date;" ?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #8

              Correct.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              P 1 Reply Last reply
              0
              • D David Crow

                Correct.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                P Offline
                P Offline
                Pavlex4
                wrote on last edited by
                #9

                What is problem with that line?

                L D 2 Replies Last reply
                0
                • P Pavlex4

                  What is problem with that line?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #10

                  Nothing.

                  P 1 Reply Last reply
                  0
                  • L Lost User

                    Nothing.

                    P Offline
                    P Offline
                    Pavlex4
                    wrote on last edited by
                    #11

                    I added date = new Date(); to button onclicklistener but when I click button inside app it gets pressed and stays like that and nothing happens!!!

                    button.setOnClickListener(new View.OnClickListener()
                    {
                    @Override
                    public void onClick(View view)
                    {
                    String dayOfWeek;
                    boolean isValid;

                                **date = new Date();**
                    
                                Calendar c = Calendar.getInstance();
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd\_HHmmss");
                                String strDate = sdf.format(c.getTime());
                    
                    L 1 Reply Last reply
                    0
                    • P Pavlex4

                      I added date = new Date(); to button onclicklistener but when I click button inside app it gets pressed and stays like that and nothing happens!!!

                      button.setOnClickListener(new View.OnClickListener()
                      {
                      @Override
                      public void onClick(View view)
                      {
                      String dayOfWeek;
                      boolean isValid;

                                  **date = new Date();**
                      
                                  Calendar c = Calendar.getInstance();
                                  SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd\_HHmmss");
                                  String strDate = sdf.format(c.getTime());
                      
                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #12

                      You really need to make more effort to do some debugging of your code first. You have a problem which could be caused by any part of your code, so you need to do the troubleshooting to collect more information. Also you have a try/catch block in your code that reads:

                              try
                                  {
                                      String getdate = spinner.getItemAtPosition(position).toString() + value
                                              + textView2.getText().toString();
                                      Date date = sdf.parse(getdate);
                                  }
                                  catch (ParseException ex)
                                  {
                      
                                  }
                      

                      Do not do this, you are just hiding any problems that may occur. Put some proper code in the catch block to help you find errors.

                      1 Reply Last reply
                      0
                      • P Pavlex4

                        What is problem with that line?

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #13

                        Can you not see that you have two Date objects (in separate scopes)?

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                        L 1 Reply Last reply
                        0
                        • D David Crow

                          Can you not see that you have two Date objects (in separate scopes)?

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #14

                          Why check your own code when you can get it done for free at CodeProject? ;P

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups