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

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

已經(jīng)拋出異常為什么還是未報告異常?

已經(jīng)拋出異常為什么還是未報告異常?

慕哥9229398 2019-03-01 10:35:24
自己用javafx練習(xí)組合框時寫了一個小程序,使用到了文件輸入,但是調(diào)用需要拋出異常的函數(shù)時,明明已經(jīng)拋出了,為什么還提示未報告異常? import javafx.application.Application; import javafx.stage.Stage; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import java.util.*; public class ComboBoxDemo extends Application { private String[] flagTitle = {"Canada","America","China"}; private ImageView[] flagImage = {new ImageView("card/canada.gif"),new ImageView("card/america.gif"),new ImageView("card/china")}; private String[] flagDescription = {"Canada.txt","America.txt","China.txt"}; private DescriptionPane descriptionPane = new DescriptionPane(); private ComboBox<String> cbo = new ComboBox<>(); @Override public void start(Stage primaryStage) throws Exception { setDisplay(0); BorderPane pane = new BorderPane(); BorderPane paneForComboBox = new BorderPane(); paneForComboBox.setLeft(new Label("Select a Country")); paneForComboBox.setCenter(cbo); pane.setTop(paneForComboBox); cbo.setPrefWidth(400); cbo.setValue("Canada"); ObservableList<String> item = FXCollections.observableArrayList(flagTitle); cbo.getItems().addAll(item); pane.setCenter(descriptionPane); ***cbo.setOnAction(e->setDisplay(item.indexOf(cbo.getValue())));*** Scene scene = new Scene(pane,400,500); primaryStage.setTitle("ComboBoxDemo"); primaryStage.setScene(scene); primaryStage.show(); } public void setDisplay(int index) throws Exception { descriptionPane.setTitle(flagDescription[index]); descriptionPane.setImage(flagImage[index]); descriptionPane.setDescription(flagDescription[index]); } } import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.control.ContentDisplay; import javafx.scene.control.ScrollPane; import javafx.scene.control.TextArea; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.text.Text; import javafx.scene.text.Font; import java.util.Scanner; import java.io.File; public class DescriptionPane extends BorderPane { private Label lblImageTitle = new Label(); private TextArea taDescription = new TextArea(); public DescriptionPane() { lblImageTitle.setContentDisplay(ContentDisplay.TOP); lblImageTitle.setPrefSize(200,200); lblImageTitle.setFont(new Font("SansSerif",16)); taDescription.setFont(new Font("Serif",14)); taDescription.setEditable(false); taDescription.setWrapText(true); ScrollPane scrollPane = new ScrollPane(taDescription); setLeft(lblImageTitle); setCenter(scrollPane); setPadding(new Insets(5,5,5,5)); } public void setTitle(String title) { lblImageTitle.setText(title); } public void setImage(ImageView icon) { lblImageTitle.setGraphic(icon); } public void setDescription(String name) throws Exception { File file = new File(name); String description = new Scanner(file).next(); taDescription.setText(description); } } D:javaJCComboBoxDemo.java:38: 錯誤: 未報告的異常錯誤Exception; 必須對其進(jìn)行捕獲或聲明以便拋出 cbo.setOnAction(e->setDisplay(item.indexOf(cbo.getValue()))); 作為菜鳥的我百思不得其解·自己弄了一下午了!
查看完整描述

6 回答

?
莫回?zé)o

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

你應(yīng)該試一下用try-catch

查看完整回答
反對 回復(fù) 2019-03-01
?
PIPIONE

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

單單拋的話,并不會捕捉異常,要try catch捕捉拋出的異常進(jìn)行你的處理

查看完整回答
反對 回復(fù) 2019-03-01
?
慕運維8079593

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

public void start(Stage primaryStage) throws Exception{}

你的這個方法你用了throws Exception拋出異常,當(dāng)你調(diào)用這個方法時,必須把這個方法放在try{}catch里捕獲,你直接調(diào)用這個方法不用try{}catch,當(dāng)這個方法發(fā)生錯誤時,就會報你出現(xiàn)的那個錯誤。
另外try{}catch是為了捕獲別人的異常,throws是把異常拋給別人

查看完整回答
反對 回復(fù) 2019-03-01
  • 6 回答
  • 0 關(guān)注
  • 860 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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