第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問這段代碼哪里有問題?如何修改? 提前感謝!

請問這段代碼哪里有問題?如何修改? 提前感謝!

喵喔喔 2023-04-19 19:15:33
在寫一個排序算法演示程序先在主窗體中的Listener中調(diào)用engine:private class StartListener implements ActionListener{ public void actionPerformed(ActionEvent e){ int[] unsort=UnsortGenerator();  //函數(shù)返回給unsort一個數(shù)組 engine.setArray(unsort); engine.setAlgorithm(getAlgorithm()); engine.setSleepTime(jslSpeed.getValue()*50); engine.setHistogram(histogram);  //Histogram是用來畫柱狀圖的 engine.run(); } }然后在Engine中:private SelectionSort selectionSort=new SelectionSort();...if (thread != null && thread.getState() != Thread.State.TERMINATED) return; thread=new Thread(selectionSort); selectionSort.setArray(unsort); thread.start();在SelectionSort中:public class SelectionSort implements Runnable{ private int[] unsort; private Histogram histogram; private int sleepTime; public void run(){ selectionSort(); } public void setArray(int[] unsort){ this.unsort=unsort; } private void selectionSort(){ int key=0; int count=0; while(count<unsort.length-1){ for(int i=key+1;i<unsort.length;i++){ if(unsort[key]>unsort[i]) key=i; } int temp=unsort[count]; unsort[count]=unsort[key]; unsort[key]=temp; count++; key=count; for(int i=0;i<unsort.length;i++) System.out.printf("%d ",unsort[i]); System.out.print('\n');//這里可以輸出正常數(shù)組 histogram.showHistogram(unsort);//這里會拋出異常 try { Thread.sleep(sleepTime); } catch (Exception ex) { ex.printStackTrace(); } } } }
查看完整描述

1 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗 獲得超2個贊

空指針異常在于histogram而不在于unsort
engine中只設(shè)置了array,再設(shè)置上histogram就可以了

查看完整回答
反對 回復(fù) 2023-04-21
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號