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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:32:25+00:00 2026-06-09T01:32:25+00:00

I am trying to write an app that will play a sound clip when

  • 0

I am trying to write an app that will play a sound clip when an image is clicked. The clip is about 1 second long. Whenever the app is opened it force closes. Here’s my coding. Why does it force close?

Main Activity

package com.jeremy.vroom;

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

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button zero = (Button)this.findViewById(R.id.btnZero);
        zero.setOnClickListener(new OnClickListener() {

            public void onClick(View view) {     
                new Thread(){
                    public void run(){
                        MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.rev);   
                        mp.start();
                    }
                }.start();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

activitymain.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >



<ImageView
    android:id="@+id/btnZero"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/uro5" 
    android:clickable="true"
    android:contentDescription="@string/desc" ></ImageView>

Log

08-03 17:21:29.156: D/AndroidRuntime(272): Shutting down VM
08-03 17:21:29.156: W/dalvikvm(272): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-03 17:21:29.298: E/AndroidRuntime(272): FATAL EXCEPTION: main
08-03 17:21:29.298: E/AndroidRuntime(272): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jeremy.vroom/com.jeremy.vroom.MainActivity}: java.lang.ClassCastException: android.widget.ImageView
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.os.Looper.loop(Looper.java:123)
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-03 17:21:29.298: E/AndroidRuntime(272):  at java.lang.reflect.Method.invokeNative(Native Method)
08-03 17:21:29.298: E/AndroidRuntime(272):  at java.lang.reflect.Method.invoke(Method.java:521)
08-03 17:21:29.298: E/AndroidRuntime(272):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-03 17:21:29.298: E/AndroidRuntime(272):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-03 17:21:29.298: E/AndroidRuntime(272):  at dalvik.system.NativeStart.main(Native Method)
08-03 17:21:29.298: E/AndroidRuntime(272): Caused by: java.lang.ClassCastException: android.widget.ImageView
08-03 17:21:29.298: E/AndroidRuntime(272):  at com.jeremy.vroom.MainActivity.onCreate(MainActivity.java:18)
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-03 17:21:29.298: E/AndroidRuntime(272):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-03 17:21:29.298: E/AndroidRuntime(272):  ... 11 more
08-03 17:21:32.588: I/Process(272): Sending signal. PID: 272 SIG: 9

Thanks in advance for any help

  • 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-09T01:32:26+00:00Added an answer on June 9, 2026 at 1:32 am

    use

    ImageView zero = (ImageView)findViewById(R.id.btnZero);
    

    instead of

     Button zero = (Button)this.findViewById(R.id.btnZero);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to write an app that will display a list off lines from
Trying to write app for service technicians that will display open service calls within
I'm trying to write a Sinatra app that will run on a shared Passenger
I'm trying to write an Android 2.2 app that will find installed apps that
Long story short: I'm trying to write an app that'll dump IE's history to
I'm trying to write a very simple terminal app that will scan for Bluetooth
I'm trying to write an Android app that will allow a user to search
I'm trying to write a very simple app that will do just one very
I am trying to write an app that will connect to a database, extract
I'm trying to write a simple app that will do a screen capture of

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.