Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android应用程序在使用线程时崩溃_Java_Android_Multithreading - Fatal编程技术网

Java Android应用程序在使用线程时崩溃

Java Android应用程序在使用线程时崩溃,java,android,multithreading,Java,Android,Multithreading,我发现了我的错误。我错过了我的静音上的视图参数 方法 我正在创建一个应用程序来播放音乐。我已经能够在专栏中循环播放声音,并实现播放/暂停功能。但是,如果我在线程运行时尝试使用任何其他UI组件(如button),则应用程序会崩溃。例如:当我按下静音按钮并调用muteSound方法时,应用程序停止工作并崩溃。线程位于playSound()方法内部 基于崩溃,您定义了一个xmlonClick来调用muteSound 但是,该方法需要接受视图参数 public void muteSound(View v

我发现了我的错误。我错过了我的静音上的视图参数 方法

我正在创建一个应用程序来播放音乐。我已经能够在专栏中循环播放声音,并实现播放/暂停功能。但是,如果我在线程运行时尝试使用任何其他UI组件(如button),则应用程序会崩溃。例如:当我按下静音按钮并调用muteSound方法时,应用程序停止工作并崩溃。线程位于playSound()方法内部


基于崩溃,您定义了一个xml
onClick
来调用
muteSound
但是,该方法需要接受
视图
参数

public void muteSound(View view)
{
  //implementation
}

您可以按如下方式使用runOnUiThread

new Thread(new Runnable() {
        public void run() {

             if (pause) { break; }

            runOnUiThread(new Runnable() {
                public void run() {

                    int col = getNextCol();
                    sequence(col);
                    txt.setText("Playing column - " + col);
                }
            });

            try { Thread.sleep(tempo); } catch (Exception e) {}
        }
    }).start();

如果应用程序崩溃,请始终发布LogCat堆栈跟踪。发现我的错误。我错过了muteSound方法的View参数。
public void muteSound(View view)
{
  //implementation
}
new Thread(new Runnable() {
        public void run() {

             if (pause) { break; }

            runOnUiThread(new Runnable() {
                public void run() {

                    int col = getNextCol();
                    sequence(col);
                    txt.setText("Playing column - " + col);
                }
            });

            try { Thread.sleep(tempo); } catch (Exception e) {}
        }
    }).start();