Android Soundboard应用程序force关闭,我可以';我不明白为什么

Android Soundboard应用程序force关闭,我可以';我不明白为什么,android,media-player,soundpool,Android,Media Player,Soundpool,所以我一直在为我的孩子们开发一个音板应用程序。这是我的第一个应用,所以你可以想象我几乎不知道我在做什么(noob),所以我提前道歉:-)。我不确定我的问题在哪里,但我的启动屏幕运行没有问题,但当它试图加载下一个活动时,它将强制关闭。我将包括我的清单java文件,该文件用于播放音频和按钮的布局,这些按钮是可单击的图像。提前谢谢!此外,我想设置它的按钮可以播放一个随机的声音,与图像使用soundpool,但再次与noobness。我对这些错误并不十分熟悉,但我认为java.land.classcas

所以我一直在为我的孩子们开发一个音板应用程序。这是我的第一个应用,所以你可以想象我几乎不知道我在做什么(noob),所以我提前道歉:-)。我不确定我的问题在哪里,但我的启动屏幕运行没有问题,但当它试图加载下一个活动时,它将强制关闭。我将包括我的清单java文件,该文件用于播放音频和按钮的布局,这些按钮是可单击的图像。提前谢谢!此外,我想设置它的按钮可以播放一个随机的声音,与图像使用soundpool,但再次与noobness。我对这些错误并不十分熟悉,但我认为java.land.classcastexception:android.widget.imageview是mymenu活动未启动的原因。希望有帮助

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pnl.thebasics"
    android:versionCode="1"
    android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<application
    android:icon="@drawable/sssicon"
    android:label="@string/app_name" >
    <activity android:label="@string/app_name" android:name=".myMain">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:label="@string/app_name" android:name=".myMenu">
        <intent-filter>
            <action android:name="com.pnl.thebasics.CLEARSCREEN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>



</application>

</manifest>


package com.pnl.thebasics;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class myMenu extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    // Hide the title bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Go full screen
    final Window window = getWindow();
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.menu);

    //these are the buttons that play sounds

    //button 1 (sponge bob)
    final MediaPlayer mpButtonClick1 = MediaPlayer.create(this, R.raw.sb1);
    Button bSpongebob = (Button) findViewById(R.id.sbbutton);
    bSpongebob.setOnClickListener(new View.OnClickListener() {

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

            mpButtonClick1.start();
        }
    });
    //button 2 (patrick)
    final MediaPlayer mpButtonClick2 = MediaPlayer.create(this, R.raw.pat1);
    Button bPatrick = (Button) findViewById(R.id.patbutton);
    bPatrick.setOnClickListener(new View.OnClickListener() {

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

            mpButtonClick2.start();
        }
    });
}



}


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

<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/sbbutton"
        android:layout_width="wrap_content"
        android:layout_height="130dp"
        android:layout_weight="50"
        android:clickable="true"
        android:src="@drawable/sbbuttonimage" />

    <ImageView
        android:id="@+id/patbutton"
        android:layout_width="wrap_content"
        android:layout_height="130dp"
        android:layout_weight="50"
        android:clickable="true"
        android:src="@drawable/patbuttonimage" />
</LinearLayout>



<LinearLayout
    android:id="@+id/LinearLayout02"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/mrcrabsbutton"
        android:layout_width="wrap_content"
        android:layout_height="130dp"
        android:layout_weight="50"
        android:clickable="true"
        android:src="@drawable/mrcrabsbuttonimage" />

    <ImageView
        android:id="@+id/squidwardbutton"
        android:layout_width="wrap_content"
        android:layout_height="130dp"
        android:layout_weight="50"
        android:clickable="true"
        android:src="@drawable/squidwardbuttonimage" />
</LinearLayout>

<LinearLayout
    android:id="@+id/LinearLayout03"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/planktonbutton"
        android:layout_width="wrap_content"
        android:layout_height="130dp"
        android:layout_weight="50"
        android:clickable="true"
        android:src="@drawable/planktonbuttonimage" />

    <ImageView
        android:id="@+id/garybutton"
        android:layout_width="wrap_content"
        android:layout_height="130dp"
        android:layout_weight="50"
        android:clickable="true"
        android:src="@drawable/garybuttonimage" />
</LinearLayout>

</LinearLayout>

包com.pnl.thebasics;
导入android.app.Activity;
导入android.media.MediaPlayer;
导入android.os.Bundle;
导入android.view.view;
导入android.view.Window;
导入android.view.WindowManager;
导入android.widget.Button;
公共类myMenu扩展活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
//隐藏标题栏
requestWindowFeature(窗口。功能\u无\u标题);
//全屏
最终窗口=getWindow();
设置标志(WindowManager.LayoutParams.FLAG_全屏,WindowManager.LayoutParams.FLAG_全屏);
setContentView(R.layout.menu);
//这些是播放声音的按钮
//按钮1(海绵鲍勃)
final MediaPlayer mpButtonClick1=MediaPlayer.create(这是R.raw.sb1);
按钮bSpongebob=(按钮)findViewById(R.id.sbbutton);
bSpongebob.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
//TODO自动生成的方法存根
mpButtonClick1.start();
}
});
//按钮2(帕特里克)
final MediaPlayer mpButtonClick2=MediaPlayer.create(this,R.raw.pat1);
按钮bPatrick=(按钮)findViewById(R.id.patbutton);
bPatrick.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
//TODO自动生成的方法存根
mpButtonClick2.start();
}
});
}
}

您的Java代码希望在布局中找到
按钮
对象:

Button bSpongebob = (Button) findViewById(R.id.sbbutton);
但是您的布局将该小部件声明为
ImageView

<ImageView
    android:id="@+id/sbbutton"

您的Java代码希望在布局中找到
按钮
对象:

Button bSpongebob = (Button) findViewById(R.id.sbbutton);
但是您的布局将该小部件声明为
ImageView

<ImageView
    android:id="@+id/sbbutton"

欢迎来到Stackoverflow!如果你觉得回复有帮助,请投票表决。如果回答成功回答了您的问题,请单击旁边的绿色复选标记以接受回答。另外,关于如何写一个好的问题,请参阅,以获得建议。您是否尝试过清理您的项目?在Eclipse上选择Project->Clean。您能给我们您的logcat的输出吗?这会告诉我们更多关于你的错误。如果你觉得我的评论有点冒犯你,我很抱歉,但是天哪,在开发一些真实世界的应用程序之前,你试着学习了一些吗??我读了你的问题,在我看来,你不懂安卓,也不懂Java。我给你的建议是买一些书,仔细阅读,尝试所有的实际例子,然后尝试开发一个应用程序。祝你好运,并致以最良好的祝愿!别管他,伊戈尔,他正在学习,其中一部分是在这里提问。欢迎来到Stackoverflow!如果你觉得回复有帮助,请投票表决。如果回答成功回答了您的问题,请单击旁边的绿色复选标记以接受回答。另外,关于如何写一个好的问题,请参阅,以获得建议。您是否尝试过清理您的项目?在Eclipse上选择Project->Clean。您能给我们您的logcat的输出吗?这会告诉我们更多关于你的错误。如果你觉得我的评论有点冒犯你,我很抱歉,但是天哪,在开发一些真实世界的应用程序之前,你试着学习了一些吗??我读了你的问题,在我看来,你不懂安卓,也不懂Java。我给你的建议是买一些书,仔细阅读,尝试所有的实际例子,然后尝试开发一个应用程序。祝你好运,并致以最良好的祝愿!别管他,伊戈尔,他正在学习,其中一部分是在这里提问。就是这样!我选择了ImageView。谢谢你的理解。我现在有一个简单的音板。我的下一个目标是让它从一组声音中随机播放一个声音,这样每个角色都会有多个谚语。我女儿已经喜欢了,就是这样!我选择了ImageView。谢谢你的理解。我现在有一个简单的音板。我的下一个目标是让它从一组声音中随机播放一个声音,这样每个角色都会有多个谚语。不过我女儿已经喜欢了。