ボタンを押すとアプリがしばらく起動し、同じボタンをクリックするとアプリが停止します。アプリが入り、サウンドを 1 回再生してからクラッシュします。なんで?
Java コード:
metronomepp.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (ms==0) {ms=1;}
while (ms == 1) {
if (metronome.isPlaying()) {metronome.pause();}
metronome.seekTo(0);
metronome.setOnSeekCompleteListener(null);
metronome.start();
metronome.setOnCompletionListener(null);
try {
wait ((long) timetw);
} catch (InterruptedException e) {
e.printStackTrace();
}
metronomepp.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.i("Metronome", "InWhile1");
ms=0;
}
});
}
}
});
ボタンを押した後の LogCat:
03-14 19:10:30.584: I/Metronome clicked(25448): 1
03-14 19:10:30.584: I/Metronome(25448): InWhile
03-14 19:10:30.584: V/MediaPlayer(25448): isPlaying: 0
03-14 19:10:30.584: V/MediaPlayer-JNI(25448): isPlaying: 0
03-14 19:10:30.584: V/MediaPlayer-JNI(25448): seekTo: 0(msec)
03-14 19:10:30.584: V/MediaPlayer(25448): seekTo 0
03-14 19:10:30.584: V/MediaPlayer(25448): getDuration
03-14 19:10:30.584: V/MediaPlayer(25448): message received msg=4, ext1=0, ext2=0
03-14 19:10:30.589: V/MediaPlayer(25448): Received seek complete
03-14 19:10:30.589: V/MediaPlayer(25448): All seeks complete - return to regularly scheduled program
03-14 19:10:30.589: V/MediaPlayer(25448): callback application
03-14 19:10:30.589: V/MediaPlayer(25448): back from callback
03-14 19:10:30.589: V/MediaPlayer-JNI(25448): start
03-14 19:10:30.589: V/MediaPlayer(25448): start
03-14 19:10:30.619: D/AndroidRuntime(25448): Shutting down VM
03-14 19:10:30.619: W/dalvikvm(25448): threadid=1: thread exiting with uncaught exception (group=0x40c581f8)
03-14 19:10:30.624: E/AndroidRuntime(25448): FATAL EXCEPTION: main
03-14 19:10:30.624: E/AndroidRuntime(25448): java.lang.IllegalMonitorStateException: object not locked by thread before wait()
03-14 19:10:30.624: E/AndroidRuntime(25448): at java.lang.Object.wait(Native Method)
03-14 19:10:30.624: E/AndroidRuntime(25448): at java.lang.Object.wait(Object.java:401)
03-14 19:10:30.624: E/AndroidRuntime(25448): at com.example.guitartools.MetronomeActivity$3.onClick(MetronomeActivity.java:72)
03-14 19:10:30.624: E/AndroidRuntime(25448): at android.view.View.performClick(View.java:3627)
03-14 19:10:30.624: E/AndroidRuntime(25448): at android.view.View$PerformClick.run(View.java:14329)
03-14 19:10:30.624: E/AndroidRuntime(25448): at android.os.Handler.handleCallback(Handler.java:605)
03-14 19:10:30.624: E/AndroidRuntime(25448): at android.os.Handler.dispatchMessage(Handler.java:92)
03-14 19:10:30.624: E/AndroidRuntime(25448): at android.os.Looper.loop(Looper.java:137)
03-14 19:10:30.624: E/AndroidRuntime(25448): at android.app.ActivityThread.main(ActivityThread.java:4511)
03-14 19:10:30.624: E/AndroidRuntime(25448): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 19:10:30.624: E/AndroidRuntime(25448): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 19:10:30.624: E/AndroidRuntime(25448): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
03-14 19:10:30.624: E/AndroidRuntime(25448): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
03-14 19:10:30.624: E/AndroidRuntime(25448): at dalvik.system.NativeStart.main(Native Method)
03-14 19:10:30.969: V/MediaPlayer(25448): message received msg=2, ext1=0, ext2=0
03-14 19:10:30.969: V/MediaPlayer(25448): playback complete
03-14 19:10:30.969: V/MediaPlayer(25448): callback application
03-14 19:10:30.969: V/MediaPlayer(25448): back from callback