所以我一直在为我的孩子们开发一个音板应用程序。这是我的第一个应用程序,因此您可以想象我几乎不知道自己在做什么(菜鸟),所以我提前道歉:-)。我不确定我的问题出在哪里,但我的启动画面运行没有问题,但是当它尝试加载下一个活动时,它会强制关闭。我将在清单中包含应该播放音频的 java 文件和可点击图像的按钮布局。提前致谢!此外,我想将其设置为按钮可以播放与使用 soundpool 的图像相关的随机声音,但又是新手。我对这些错误一点也不熟悉,但我看到 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>