我正在这样做,因此单击按钮时会发出声音,但我一直遇到错误。这是我的java代码:
package com.thisisfoo.testgame;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Main extends Activity {
MediaPlayer buttonSound;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Button sounds
final MediaPlayer buttonSound = MediaPlayer.create(Main.this, R.raw.test);
//setting up buttons
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent("com.thisisfoo.testgame"));
}
});
}
当我运行它时它会播放声音,但它会崩溃并说“不幸的是,测试已停止”。谁能帮助我。谢谢!
编辑:继承人我的logcat
02-02 22:56:29.401: E/AndroidRuntime(27328): FATAL EXCEPTION: main
02-02 22:56:29.401: E/AndroidRuntime(27328): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.thisisfoo.testgame }
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1638)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1510)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.app.Activity.startActivityForResult(Activity.java:3263)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.app.Activity.startActivity(Activity.java:3370)
02-02 22:56:29.401: E/AndroidRuntime(27328): at com.thisisfoo.testgame.Main$1.onClick(Main.java:35)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.view.View.performClick(View.java:3538)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.view.View$PerformClick.run(View.java:14319)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.os.Handler.handleCallback(Handler.java:608)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.os.Handler.dispatchMessage(Handler.java:92)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.os.Looper.loop(Looper.java:156)
02-02 22:56:29.401: E/AndroidRuntime(27328): at android.app.ActivityThread.main(ActivityThread.java:5060)
02-02 22:56:29.401: E/AndroidRuntime(27328): at java.lang.reflect.Method.invokeNative(Native Method)
02-02 22:56:29.401: E/AndroidRuntime(27328): at java.lang.reflect.Method.invoke(Method.java:511)
02-02 22:56:29.401: E/AndroidRuntime(27328): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-02 22:56:29.401: E/AndroidRuntime(27328): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-02 22:56:29.401: E/AndroidRuntime(27328): at dalvik.system.NativeStart.main(Native Method)