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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:35:31+00:00 2026-05-23T11:35:31+00:00

new android dev hopeful here. I’ve been attempting to implement an app that, upon

  • 0

new android dev hopeful here. I’ve been attempting to implement an app that, upon holding down the “ok” button, it will play the default ringtone in a loop.

What I have so far

package com.tick.helloAndroid;

import net.technologichron.android.control.NumberPicker;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
//import android.widget.TextView;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.Toast;


public class main extends Activity implements OnTouchListener {
    private int REQUEST_ENABLE_BT = 1;
    private MediaPlayer mp;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         // Set up the window layout
         setContentView(R.layout.main);

         final Button zero = (Button) this.findViewById(R.id.ok);
         zero.setOnTouchListener(this);
         Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); 
         mp.setDataSource(this, alert);

    }
    public boolean onTouch(View v, MotionEvent event) {

        switch (event.getAction()) {

        case MotionEvent.ACTION_DOWN:
            mp.setLooping(true);
            mp.start();

        case MotionEvent.ACTION_UP:
            mp.pause();
        }

        return true;
    }
}

From doing some searching on SO, this seems to work for some people, however, the line

mp.setDataSource(this, alert);

seems to not work. By not work, I mean that it forces an “Unhandled Exception Error”, which upon doing a try-catch statement,

  try {
        mp.setDataSource(this, alert);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        Toast.makeText(this, "args", Toast.LENGTH_LONG).show();
        finish();
        return;
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        Toast.makeText(this, "sec", Toast.LENGTH_LONG).show();
        finish();
        return;
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        Toast.makeText(this, "illega", Toast.LENGTH_LONG).show();
        finish();
        return;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Toast.makeText(this, "io", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

compiles without any error but crashes when I try to run the app on the android emulator, it does not print any of the above catches’ strings.

Any thoughts and ideas about what I have done incorrectly will be most appreciated.

edit: could it be from the fact that the emu does not have a ringtone?

  • 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-23T11:35:32+00:00Added an answer on May 23, 2026 at 11:35 am

    forgot to instantiate mp….hahahahha

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

Sidebar

Related Questions

Im fairly new to android dev and I want to build an app that
new Android developer here. I'm doing a form that let's users set up some
I am pretty new to Android dev. I am browsing through the API here
I am new to Android dev. The way I have been handling clicks has
I'm new to Android dev. There's a very pretty state diagram of the MediaPlayer
I'm pretty new to Android dev and still working out a lot of things.
I know that eclipse can do this, can Intellij via the new Android support
I just started to play with android dev and java+eclipse is pretty new to
I've been trying to get a handle on Dialogs. I read the android dev
I'm brand new to Android dev and have some n00b questions about AVD. Is

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.