1
ImageButtonのサウンドが開始され、次のクリックの後に停止されます。メディアプレーヤーの起動/停止 - クラッシュ
作業の開始と停止。しかし、戻るボタンを押すと、プログラムがクラッシュします。
問題はどこですか?
コード:
public class Sound extends Activity implements OnClickListener {
public int count = 0;
MediaPlayer y;
ImageButton th;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app);
th = (ImageButton)findViewById(R.id.ibFirst);
y = MediaPlayer.create(this, R.raw.th);
th.setOnClickListener(this);
count = 0;
}
public void onClick(View th) {
if(count == 0){
y.start();
count = 1;
} else {
y.pause();
count = 0;
}
}
@Override
protected void onDestroy() {
if(y != null) {
y.pause();
y.stop();
y.release();
count = 0;
}
}
}
エラー:
私はスタートをクリックすると/ /ストップ・10倍の開始、停止:私は戻るボタンを押すとD
3-02 14:21:05.395: W/MediaPlayer(233): info/warning (1, 44)
03-02 14:21:05.494: I/MediaPlayer(233): Info (1,44)
03-02 14:22:28.085: E/MediaPlayer(233): pause called in state 128
03-02 14:22:28.085: E/MediaPlayer(233): error (-38, 0)
03-02 14:22:28.085: E/MediaPlayer(233): Error (-38,0)
03-02 14:22:33.455: E/MediaPlayer(233): start called in state 0
03-02 14:22:33.455: E/MediaPlayer(233): error (-38, 0)
03-02 14:22:33.455: E/MediaPlayer(233): Error (-38,0)
03-02 14:22:35.964: W/KeyCharacterMap(233): No keyboard for id 0
03-02 14:22:35.964: W/KeyCharacterMap(233): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
03-02 14:22:36.584: E/MediaPlayer(233): pause called in state 0
03-02 14:22:36.584: E/MediaPlayer(233): error (-38, 0)
03-02 14:22:36.584: E/MediaPlayer(233): stop called in state 0
03-02 14:22:36.584: E/MediaPlayer(233): error (-38, 0)
を。
03-02 14:22:36.635: D/AndroidRuntime(233): Shutting down VM
03-02 14:22:36.635: W/dalvikvm(233): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-02 14:22:36.635: E/AndroidRuntime(233): Uncaught handler: thread main exiting due to uncaught exception
03-02 14:22:36.655: E/AndroidRuntime(233): android.app.SuperNotCalledException: Activity {com.troll.sound/com.troll.sound.Sound} did not call through to super.onDestroy()
03-02 14:22:36.655: E/AndroidRuntime(233): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3458)
03-02 14:22:36.655: E/AndroidRuntime(233): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3487)
03-02 14:22:36.655: E/AndroidRuntime(233): at android.app.ActivityThread.access$2800(ActivityThread.java:119)
03-02 14:22:36.655: E/AndroidRuntime(233): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896)
03-02 14:22:36.655: E/AndroidRuntime(233): at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 14:22:36.655: E/AndroidRuntime(233): at android.os.Looper.loop(Looper.java:123)
03-02 14:22:36.655: E/AndroidRuntime(233): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-02 14:22:36.655: E/AndroidRuntime(233): at java.lang.reflect.Method.invokeNative(Native Method)
03-02 14:22:36.655: E/AndroidRuntime(233): at java.lang.reflect.Method.invoke(Method.java:521)
03-02 14:22:36.655: E/AndroidRuntime(233): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-02 14:22:36.655: E/AndroidRuntime(233): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-02 14:22:36.655: E/AndroidRuntime(233): at dalvik.system.NativeStart.main(Native Method)
03-02 14:22:36.685: I/dalvikvm(233): threadid=7: reacting to signal 3
03-02 14:22:36.714: E/dalvikvm(233): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
どのようにしてクラッシュを引き起こすのでしょうか?ログを提供してください.. –
"super.onDestroy()にコールしなかった"という問題が1つあります。 –