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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:36:06+00:00 2026-05-24T12:36:06+00:00

When trying to make a sound when clicked on an ImageButton my application crashes

  • 0

When trying to make a sound when clicked on an ImageButton my application crashes and I’ve been staring at my code for quite some time now without finding an answer. I was hoping you guys could help me see what I’m doing wrong.

I tried to make the onClick event manually with the imageButton which failed and then I tried it through the drag and drop system of Eclipse, which made the button clickable through a method I named test123 via the main.xml.

I’ll post my code and hope you guys can find a sollution.

Thanks in advance,

package com.example.Jeffrey;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class Jeffrey extends Activity {
MediaPlayer mp;

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

    mp = MediaPlayer.create(this, R.raw.noise);

   // View rakker = findViewById(R.id.imageView1);
    //rakker.setOnClickListener(this);

}

public void test123()
{        
    mp.start();

}

}

The xml that goes with the code:

<ImageButton 
android:src="@drawable/rakker" 
android:layout_height="250px" 
android:layout_width="wrap_content" android:id="@+id/imageView1"
android:onClick="test123"></ImageButton>
  • 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-24T12:36:07+00:00Added an answer on May 24, 2026 at 12:36 pm

    It’s probably worth checking for a null value considering it returns that if for any reason it fails to create the MediaPlayer object. Also, it should probably get released when finished (also with a null check).

    EDIT:

    while my earlier answer might be worth considering, it is definitely necessary that you have your onClick method take a View as a parameter.

    //at the top of the file
    
    import android.view.View;
    
    public void test123(View v){
        //v is the view that has been clicked (the ImageButton from your .xml file)
        //do stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a small application for learning Morse code and I
Trying to make a MySQL-based application support MS SQL, I ran into the following
I'm trying to make a siren sound in python with beeps, but had no
I've been trying to create a sound library as a learning project. I get
I'm trying to make a HTML5 webapp that simply plays a sound over and
I'm trying to make sense of some crash logs I received for my iPhone
I'm trying to develop an online application where the user writes some text and
I'm trying to make a custom sound play on a status bar notification. The
I'm trying to make a simple piano application in C#. It's supposed to be
I am trying to make a very precisely timed firing of a sound. I

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.