Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6742829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:53:22+00:00 2026-05-26T11:53:22+00:00

The title of this problem describes my problem. I have tried fixing this for

  • 0

The title of this problem describes my problem. I have tried fixing this for a while and i am tired of searching and would like some help please. It used to work until I added the Handler and runner. I am trying to make an application that is a simple clock application that the user can set to any time that they want to. Whenever I go to run the application, it opens and then says it would not start properly. This is an activity that is set by another activity and then it changes the values it receives, it also displays these values in textviews.

   package CoopFun.Clocks;

  import android.os.Bundle;
  import android.os.Handler;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.Window;
  import android.widget.TextView;
  import android.content.Intent;
  import android.app.Activity;

public class ClockMain extends Activity {

int Hours;
int Minutes;
int Seconds;

String TimeOfDayS;

TextView HoursMainV;
TextView MinutesMainV;
TextView SecondsMainV;
TextView TimeOfDayMainV;

Timer oneSecond;



public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.clock_main);
    requestWindowFeature(Window.FEATURE_NO_TITLE);


    Bundle extras = getIntent().getExtras();
        if (extras == null) {
            return;
        }
    int Hour = extras.getInt("HoursS");
    Hour = Hours;
    int Minute = extras.getInt("MinutesS");
    Minute = Minutes;
    int Second = extras.getInt("SecondsS");
    Second = Seconds;
    String TimeOfDaySs = extras.getString("TimeOfDayS");
    TimeOfDaySs = TimeOfDayS;

    HoursMainV = (TextView) findViewById(R.id.HoursMainV);
    HoursMainV.setText(""+Hour);

    MinutesMainV = (TextView) findViewById(R.id.MinutesMainV);
    MinutesMainV.setText(":"+Minute);

    SecondsMainV = (TextView) findViewById(R.id.SecondsMainV);
    SecondsMainV.setText(":"+Second);

    TimeOfDayMainV = (TextView) findViewById(R.id.TimeOfDayMainV);
    TimeOfDayMainV.setText(" "+TimeOfDaySs);
    final Handler handler=new Handler();
    final Runnable r = new Runnable()
    {
        public void run() 
        {
            ++Seconds;
            if(Seconds == 60){
                ++Minutes;
                Seconds = 0;
                if(Minutes == 60) {
                    ++Hours;
                    Minutes = 0;
                    if(Hours == 12){
                        if(TimeOfDayS.equals("AM")) {
                            TimeOfDayS = "PM";
                        } else{
                            TimeOfDayS = "AM";
                        }
                        Hours = 0;
                    }
                }
            }
            HoursMainV.append(""+Hours);
            if(Minutes <=9) {
                MinutesMainV.append(":0"+Minutes);
            } else {
                MinutesMainV.append(":"+Minutes);
            }
            if(Seconds <=9) {
                SecondsMainV.append(":0"+Seconds);
            } else {
                SecondsMainV.append(":"+Seconds);
            }
            TimeOfDayMainV.append(" " + TimeOfDayS);
            handler.postDelayed(this, 1000);
        }
    };

    handler.postDelayed(r, 1000);
}
}

XML:

       <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="wrap_content"
             android:layout_height="wrap_content" 
             android:orientation="horizontal">
       <TextView 
     android:textSize="50dip" 
             android:id="@+id/HoursMainV" 
             android:layout_width="wrap_content" 
             android:layout_height="wrap_content" 
             android:layout_marginLeft="25dip"></TextView>
          <TextView 
            android:textSize="50dip" 
        android:id="@+id/MinutesMainV" 
            android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></TextView>
         <TextView 
        android:textSize="50dip" 
        android:id="@+id/SecondsMainV" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></TextView>
         <TextView 
        android:textSize="50dip" 
        android:id="@+id/TimeOfDayMainV" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></TextView>
    </LinearLayout>

Manifest:

    <?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="CoopFun.Clocks"
  android:versionCode="1"
  android:versionName="1.0">


<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Clock"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
        <activity android:name=".ClockMain">
    </activity>

</application>
</manifest>

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:53:23+00:00Added an answer on May 26, 2026 at 11:53 am
    int Hour = extras.getInt("HoursS");
    Hour = Hours;
    int Minute = extras.getInt("MinutesS");
    Minute = Minutes;
    int Second = extras.getInt("SecondsS");
    Second = Seconds;
    String TimeOfDaySs = extras.getString("TimeOfDayS");
    TimeOfDaySs = TimeOfDayS;
    

    Change above code with this::

    int Hour = extras.getInt("HoursS");
    Hours = Hour;
    int Minute = extras.getInt("MinutesS");
    Minutes = Minute;
    int Second = extras.getInt("SecondsS");
    Seconds = Second;
    String TimeOfDaySs = extras.getString("TimeOfDayS");
    TimeOfDayS = TimeOfDaySs;
    

    Simply, u were getting null pointer exception bcoz u were setting null values to Hour,Minute,Second and TimeOfDaySs and accessing them.

    Cheers….!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed some similar questions about this problem when I typed the title, but
I have no good title for this question, but my problem is to set
I have this function above to create url slugs from posts title, the problem
Hello everybody, I have this problem (title of the post). Failure/Error: get :create, :user
I'm sorry if this title doesn't describe the problem properly but I wasn't sure
Hard to come up with a proper title for this problem. Anyway... I'm currently
Sorry for the vague title, as I really can't explain this problem succinctly. Basically
Yes I know, this title isn't really helpfull but this is the exact problem.
I know the title is somewhat confusing, my problem is this: I want to
excuse me in advance if this is not the right title for the problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.