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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:20:43+00:00 2026-06-18T15:20:43+00:00

My app keeps crashing when I click the startButton. I guess the problem is

  • 0

My app keeps crashing when I click the “startButton”. I guess the problem is somewhere within that onTouch method, but I’ve tried solving the problem for hours; disabling different things inside the startButton.setOnTouchListener doesn’t make a difference. Can you find anything wrong?

MediaPlayer mp;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    final Button startButton = (Button) this.findViewById(R.id.button1);
    final TextView timeLeft = (TextView) this.findViewById(R.id.timeLeft);
    MediaPlayer.create(getBaseContext(), R.raw.songthingy);


    startButton.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {

                mp.start();
                timeLeft.setText("Status: Initiated");
                startButton.setText("Stop");

                startButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        mp.release();

                    }

                });

                new CountDownTimer(30000, 1000) {

                    public void onTick(long millisUntilFinished) {
                        timeLeft.setText("Status: Starting in... "
                                + millisUntilFinished / 1000);
                    }

                    public void onFinish() {
                        timeLeft.setText("Status: Finished");
                    }
                }.start();

                mp.setOnCompletionListener(new OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        mp.release();
                    }
                });
            }
            ;
            return true;
        }
    });

}
  • 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-18T15:20:44+00:00Added an answer on June 18, 2026 at 3:20 pm

    There is no exception stack in question, but one issue I see is:

    MediaPlayer mp;
    

    is pointed to null and you are calling

    mp.start();

    in OnTouchListener, which results in NullPointerException.

    I think what you need to do is:

     final TextView timeLeft = (TextView) this.findViewById(R.id.timeLeft);
     mp= MediaPlayer.create(getBaseContext(), R.raw.songthingy);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A .Net 4.0 app keeps crashing for a user, but just for him, I
I have been trying to fix this problem for hours. My app keeps crashing
an app I'm working on keeps crashing when run on the iPhone but not
I just discovered that my nodejs app keeps crashing, so I've used forever app.js
I am having some problems with an app that keeps crashing intermittently. Code below
I'm trying to implement async on Android but it keeps crashing my app, the
Im not sure why, but my app all of a sudden keeps force closing
My application keeps crashing when I type something in a EditText, but this does
My server keeps crashing. It is especially bad in localized parts of my app
My 'game' keeps crashing after I resume it. Basically, I launch the app and

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.