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 8466177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:15:54+00:00 2026-06-10T15:15:54+00:00

Hey i recently got into android and made my first app which was meant

  • 0

Hey i recently got into android and made my first app which was meant to start a run down timer of 60 seconds when the user pressed start button. The application sets the content view fine and displays 60 but when i click the start button it displays 59 successfully and then the app crashes.Here’s the code(it has only one activity)

public class test1activity extends Activity 
{   
Thread countdown;
long f, pa, jee;
TextView ytvp;
String s;
TextView uyti;
@Override   
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ytvp = (TextView) findViewById(R.id.textView2);
        uyti = (TextView) findViewById(R.id.tv2);

countdown = new Thread() {
            public void run() {
                jee = (System.currentTimeMillis()) / 1000;
                while ((((System.currentTimeMillis()) / 1000) - jee) < 60)
                                {                   
                                try {   
                    sleep(1000);    
                } catch (InterruptedException e) {                  
                    e.printStackTrace();    
                } finally {
                    f = ((System.currentTimeMillis()) / 1000) - jee;
                        pa = 60 - f;    
                        s = String.valueOf(pa);
                        ytvp.setText(s);
                    }
                }
                                }
                };
    }       
public void whenclickstart(View view) {
        countdown.start();
    }       
  • 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-06-10T15:15:56+00:00Added an answer on June 10, 2026 at 3:15 pm

    You cannot set UI elements from inside another thread(Non UI thread). So you cannot use this below line.

     ytvp.setText(s);
    

    Try something like this, you dont need threading for what you are trying to do

    new CountDownTimer(60000, 1000) {
    
         public void onTick(long millisUntilFinished) {
             ytvp.setText("" + millisUntilFinished/1000);
         }
    
         public void onFinish() {
              ytvp.setText(""+0);
         }
      }.start();
    

    If you do not want to use countdowntimer replace setText with

    runOnUiThread(new Runnable() {
        public void run() {
            ytvp.setText(s);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, So I recently got a VPS, just so I can start gaining
Hey I can't figure out an error I got. I had my App working
Hey i recently started android development and encountered a problem when saving/loading data from
Hey all. Something which has been bugging me quite a bit recently is this
Hey everyone! Started programming with Bluetooth on Android awhile ago. But now I've run
*Hey , I have finished developing my app In my iphone apps I have
Hey I just started dabbling with android programming, and from my short period of
hey i followed a ruby on rails guide when i tried to run it
I recently got projects that runs on Struts and I am expecting more JSP
Okay, so recently I've been reading into ninject but I am having trouble understanding

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.