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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:14:12+00:00 2026-06-10T01:14:12+00:00

This code is not working.. Can anyone help me out. when i had run

  • 0

This code is not working.. Can anyone help me out. when i had run this code is gave an error saying force close application.I want to start a new sound with
each click. here i am using images as my buttons.

package com.kle;

import java.io.IOException;

import com.kle.Kid.R;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
//import android.widget.Button;
import android.widget.ImageView;


public class Thirteen extends Activity implements OnClickListener{

int flag=1;
//Button b1;
MediaPlayer mp1,mp2,mp3,mp4,mp5,mp6,mp7,mp8,mp9,mp10;


ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.thirteen);

    iv=(ImageView) findViewById(R.id.imageView1);

    ImageView image1=(ImageView) findViewById(R.id.imageView1);
    ImageView image2=(ImageView) findViewById(R.id.imageView2);
    ImageView image3=(ImageView) findViewById(R.id.imageView3);
    ImageView image4=(ImageView) findViewById(R.id.imageView4);
    ImageView image5=(ImageView) findViewById(R.id.imageView5);
    ImageView image6=(ImageView) findViewById(R.id.imageView6);
    ImageView image7=(ImageView) findViewById(R.id.imageView7);
    ImageView image8=(ImageView) findViewById(R.id.imageView8);
    ImageView image9=(ImageView) findViewById(R.id.imageView9);
    ImageView image10=(ImageView) findViewById(R.id.imageView10);

    //b1= (Button) findViewById(R.id.button1);
    mp1= MediaPlayer.create(Thirteen.this, R.raw.one);
    mp2= MediaPlayer.create(Thirteen.this, R.raw.two);
    mp3= MediaPlayer.create(Thirteen.this, R.raw.three);
    mp4= MediaPlayer.create(Thirteen.this, R.raw.four);
    mp5= MediaPlayer.create(Thirteen.this, R.raw.five);
    mp6= MediaPlayer.create(Thirteen.this, R.raw.six);
    mp7= MediaPlayer.create(Thirteen.this, R.raw.seven);
    mp8= MediaPlayer.create(Thirteen.this, R.raw.eight);
    mp9= MediaPlayer.create(Thirteen.this, R.raw.nine);
    mp10= MediaPlayer.create(Thirteen.this, R.raw.ten);


    image1.setOnClickListener(this);
    image2.setOnClickListener(this);
    image3.setOnClickListener(this);
    image4.setOnClickListener(this);
    image5.setOnClickListener(this);
    image6.setOnClickListener(this);
    image7.setOnClickListener(this);
    image8.setOnClickListener(this);
    image9.setOnClickListener(this);
    image10.setOnClickListener(this);
    //b1.setOnClickListener(this);






}

public void onClick(View v) {
    // TODO Auto-generated method stub


    switch(v.getId()){

    case R.id.imageView1: {
        iv.setImageResource(R.drawable.kidone);
        mp2.stop();
        mp3.stop();
        mp4.stop();
        mp5.stop();
        mp6.stop();
        mp7.stop();
        mp8.stop();
        mp9.stop();
        mp10.stop();

        try {
            mp1.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mp1.seekTo(0);
        mp1.start();


        break;
    }
    case R.id.imageView2: {
        iv.setImageResource(R.drawable.kidtwo);
        mp1.stop();
        mp3.stop();
        mp4.stop();
        mp5.stop();
        mp6.stop();
        mp7.stop();
        mp8.stop();
        mp9.stop();
        mp10.stop();

        try {
            mp2.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mp2.seekTo(0);
        mp2.start();





        break;
    }
    case R.id.imageView3: {
        iv.setImageResource(R.drawable.kidthree);

        mp2.stop();
        mp1.stop();
        mp4.stop();
        mp5.stop();
        mp6.stop();
        mp7.stop();
        mp8.stop();
        mp9.stop();
        mp10.stop();

        try {
            mp3.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mp3.seekTo(0);
        mp3.start();



        break;
    }    
  • 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-10T01:14:13+00:00Added an answer on June 10, 2026 at 1:14 am

    First of all you must check your logcat for the exceptions so that it would be easier for you to find the source of the problem.
    Now for your problem: you’re stopping a media player which isn’t playing…
    Add a check before stopping the media player:

    private void stopPlaying(MediaPlayer mp)
    {
         if (mp != null && mp.isPlaying())
         {
              mp.stop();
         }
    }
    

    And call:

    stopPlaying(mp1);
    stopPlaying(mp2);
    stopPlaying(mp3);
    ...
    

    (Although I would prefer using an array for this kind of coding as it would make the code far more readable and easier to maintain – using loops).

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

Sidebar

Related Questions

This code is not working. Can anyone help me out? Private Sub txtErrorComment_5_LostFocus() If
Can anyone tell me why this code would not be working? $('body').on('test', function() {
runat=server /> But this code is not working How can I add multiple controls
I want to display data from database in DataGridView...This is my code...Its not working...Can
I want to know i can do something similar to this (not working) code
Can anyone help me with this? I have not been able to find anything
i have tried this code to redirect a php page.but it s not working
I am trying to execute this code for a listbox but its not working,
Got this line of code here but its not working. private void Button_Click(object sender,
My jquery code It's not working when $(a).on(hover,function(){$(this).css(background,#ccc);},function(){$(this).css(background,#fff)}); But is working when $(a).hover(function(){$(this).css(background,#ccc);},function(){$(this).css(background,#fff)}); How

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.