gpt4 book ai didi

android - 崩溃时进入Android应用

转载 作者:行者123 更新时间:2023-12-03 17:39:20 25 4
gpt4 key购买 nike

当我按下一个按钮时,我的应用程序应该启动一会儿,然后在单击该按钮时停止它。应用会进入一段时间并播放一次声音,然后崩溃。为什么?

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

最佳答案

您可能想尝试使用runOnUiThread()。您需要一个单独的线程。您不希望自己的UI线程为sleepwait
Here is a related SO question

关于android - 崩溃时进入Android应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15417338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com