0

実行中のスレッドを停止しようとすると、ヌル ポインター例外が発生する理由がわかりません。ftprun.requestStop()はアプリケーションが停止するように while ループの値を設定します。

public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        JButton btn = (JButton) e.getSource();
        Thread ftpthread= null;
        LocalFTP ftprun = null;

        switch (e.getActionCommand()) {
        case "Start Sorter":
            if(ftp) {
                JOptionPane.showMessageDialog(frame, "Sorter and ftp cannot run at the same time");
            } else {
                sorter=true;
                btn.setText("Stop Sorter");
                btn.setBackground(SystemColor.green);
            }
            break;
        case "Start ftp":
            if(sorter) {
                JOptionPane.showMessageDialog(frame, "Sorter and ftp cannot run at the same time");
            } else {
                ftp=true;
                btn.setText("Stop ftp");
                btn.setBackground(SystemColor.green);
                Config config = new Config();
                try {
                    File cf= new File(Configfile.configfile);
                    if (cf.exists()) {
                        config=ConfigurationTools.openconfig(Configfile.configfile);
                    }
                    else {
                        ConfigurationTools.writeconfig(Configfile.configfile, config);
                    }
                } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }

                ftprun= new LocalFTP(config,config.getlocalftpinterval());

                ftpthread=new Thread (ftprun);

                ftpthread.start();

            }
            break;
        case "Start Uploader":
            uploader=true;
            btn.setText("Stop Uploader");
            btn.setBackground(SystemColor.green);
            break;  
        case "Stop Sorter":
            sorter=false;
            btn.setText("Start Sorter");
            btn.setBackground(SystemColor.menu);
            break;
        case "Stop ftp":
            ftp=false;
            btn.setText("Start ftp");
            btn.setBackground(SystemColor.menu);
            ftprun.requestStop();
            break;
        case "Stop Uploader":
            uploader=false;
            btn.setText("Start Uploader");
            btn.setBackground(SystemColor.menu);
            break;  

        }
    }

助言がありますか。Thread および runnable 変数を static に設定しようとしましたが、エラーが発生しました。

4

2 に答える 2