- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Java FX 时遇到问题 我目前正在尝试序列化一个对象,为此我正在创建一个将对象从 javaFX 转换为可序列化对象的类。但是当我试图加载回对象时,我得到了
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.control.MenuItem.fire(MenuItem.java:462)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1405)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$343(ContextMenuContent.java:1358)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 43 more
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.add(Unknown Source)
at java.util.AbstractList.add(Unknown Source)
at view.OverviewInterroController.handleLoad(OverviewInterroController.java:172)
... 53 more
导致它的代码:
package model;
import java.io.Serializable;
import java.util.ArrayList;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
public class QuestionSerializable implements Serializable {
private final String question;
private final String typeReponse;
private final int nbLignesReponse;
private final ArrayList<String> reponseData = new ArrayList<String>();
public QuestionSerializable(QuestionModel model)
{
this.question = model.getQuestion().getValue();
this.typeReponse = model.getTypeReponse().getValue();
this.nbLignesReponse = model.getNbLignesReponse().getValue();
for(StringProperty val : model.getReponseData().getValue())
{
reponseData.add(val.getValue());
}
}
public QuestionModel convert()
{
QuestionModel qm = new QuestionModel(question);
qm.getNbLignesReponse().setValue(this.nbLignesReponse);
qm.getTypeReponse().setValue(typeReponse);
ObjectProperty<ObservableList<StringProperty>> reponseData2 =qm.getReponseData();
for(String val : reponseData)
{
reponseData2.getValue().add(new SimpleStringProperty(val));
}
return qm;
}
}
特别是:
ObjectProperty<ObservableList<StringProperty>> reponseData2 =qm.getReponseData();
for(String val : reponseData)
{
reponseData2.getValue().add(new SimpleStringProperty(val));
}
和 OverviewController
package view;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import com.itextpdf.text.xml.simpleparser.handler.NeverNewLineHandler;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.FileChooser;
import model.QuestionModel;
import model.QuestionSerializable;
import principale.Main;
public class OverviewInterroController {
@FXML
private TableView<QuestionModel> questionTable;
@FXML
private TableColumn<QuestionModel,String> questionColumn;
@FXML
private Label questionLabel;
@FXML
private Label typeLabel;
@FXML
private Label nbLigneLabel;
@FXML
private TableView<StringProperty> reponseTable;
@FXML
private TableColumn<ObservableList<StringProperty>,String> reponseColumn;
// Reference to the main application.
private Main mainApp;
@FXML
private void initialize()
{
questionColumn.setCellValueFactory(cellData -> cellData.getValue().getQuestion());
showQuestionDetails(null);
questionTable.getSelectionModel().selectedItemProperty().addListener(
(observable,oldvalue,newValue)-> showQuestionDetails(newValue));
}
public void showReponseTable(QuestionModel question)
{
if(question.getTypeReponse().getValue().equals("Cocher"))
{
reponseTable.setItems(question.getReponseData().getValue());
reponseColumn.setCellValueFactory(new PropertyValueFactory<>("value"));
reponseTable.setVisible(true);
}else
{
this.reponseTable.setVisible(false);
}
}
public void setMainApp(Main mainApp) {
this.mainApp = mainApp;
questionTable.setItems(mainApp.getQuestionData());
}
public void handleImprimer()
{
mainApp.showImprimerDialog();
}
public void handleClose()
{
System.exit(0);
}
public void showQuestionDetails(QuestionModel question)
{
if(question != null)
{
questionLabel.setText(question.getQuestion().getValue());
typeLabel.setText(question.getTypeReponse().getValue());
nbLigneLabel.setText(Integer.toString(question.getNbLignesReponse().getValue()));
reponseTable.setItems(FXCollections.emptyObservableList());
showReponseTable(question);
}else
{
questionLabel.setText("");
typeLabel.setText("");
nbLigneLabel.setText("0");
reponseTable.setVisible(false);
}
}
public void handleDelete()
{
int selectedIndex = questionTable.getSelectionModel().getSelectedIndex();
if(selectedIndex>=0)
{
questionTable.getItems().remove(selectedIndex);
}else
{
Alert alert = new Alert(AlertType.ERROR);
alert.initOwner(mainApp.getPrimaryStage());
alert.setTitle("Aucune question séléctionnée !");
alert.setContentText("Veuillez séléctionner une question valide !");
alert.showAndWait();
}
}
public void handleSave() throws IOException
{
FileChooser fileChooser = new FileChooser();
//Set extension filter
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("CTRL Files (*.ctrl)", "*.ctrl");
fileChooser.getExtensionFilters().add(extFilter);
//Show save file dialog
File file = fileChooser.showSaveDialog(this.mainApp.getPrimaryStage());
if(file != null){
FileOutputStream fout = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fout);
ArrayList<QuestionSerializable> qs = new ArrayList<QuestionSerializable>();
for(QuestionModel qm : this.mainApp.getQuestionData())
{
qs.add( new QuestionSerializable(qm));
}
oos.writeObject(new ArrayList<QuestionModel>(this.mainApp.getQuestionData()));
oos.close();
fout.close();
}
}
@SuppressWarnings("unchecked")
public void handleLoad() throws Exception
{
FileChooser fileChooser = new FileChooser();
//Set extension filter
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("CTRL Files (*.ctrl)", "*.ctrl");
fileChooser.getExtensionFilters().add(extFilter);
//Show save file dialog
File file = fileChooser.showSaveDialog(this.mainApp.getPrimaryStage());
if(file != null){
FileInputStream fout = new FileInputStream(file);
ObjectInputStream oos = new ObjectInputStream(fout);
ArrayList<QuestionSerializable> qm = (ArrayList<QuestionSerializable>) oos.readObject();
ObservableList<QuestionModel> qo = FXCollections.emptyObservableList();
for(QuestionSerializable q : qm)
{
qo.add(q.convert());
}
this.mainApp.setQuestionData(qo);
this.questionTable.refresh();
this.showQuestionDetails(null);
oos.close();
fout.close();
}
}
public void handleNew()
{
QuestionModel tempQuestion = new QuestionModel("");
tempQuestion.getReponseData().getValue().add(new SimpleStringProperty(""));
boolean okClicked = mainApp.showPersonEditDialog(tempQuestion);
if (okClicked) {
mainApp.getQuestionData().add(tempQuestion);
}
}
public void handleEdit()
{
QuestionModel selectedQuestion = questionTable.getSelectionModel().getSelectedItem();
if(selectedQuestion!=null)
{
boolean okClicked = mainApp.showPersonEditDialog(selectedQuestion);
if (okClicked) {
showQuestionDetails(selectedQuestion);
this.reponseTable.refresh();
}
}else
{
Alert alert = new Alert(AlertType.ERROR);
alert.initOwner(mainApp.getPrimaryStage());
alert.setTitle("Aucune question séléctionnée !");
alert.setContentText("Veuillez séléctionner une question valide !");
alert.showAndWait();
}
}
}
第 172 行是:
ObservableList<QuestionModel> qo = FXCollections.emptyObservableList();
for(QuestionSerializable q : qm)
{
qo.add(q.convert());
}
问题模型类:
package model;
import java.io.Serializable;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class QuestionModel{
private final StringProperty question;
private final StringProperty typeReponse = new SimpleStringProperty("Remplir Ligne");
private final IntegerProperty nbLignesReponse = new SimpleIntegerProperty(1);
private ObjectProperty<ObservableList<StringProperty>> reponseData = new SimpleObjectProperty<ObservableList<StringProperty>>(FXCollections.observableArrayList());
/**
* @return the reponseData
*/
public ObjectProperty<ObservableList<StringProperty>> getReponseData() {
return reponseData;
}
public void setReponseData(ObjectProperty<ObservableList<StringProperty>> reponseData)
{
this.reponseData = reponseData;
}
public QuestionModel(String question)
{
this.question = new SimpleStringProperty(question);
}
/**
* @return the nbLignesReponse
*/
public IntegerProperty getNbLignesReponse() {
return nbLignesReponse;
}
/**
* @return the question
*/
public StringProperty getQuestion() {
return question;
}
/**
* @return the typeReponse
*/
public StringProperty getTypeReponse() {
return typeReponse;
}
}
最佳答案
FXCollections.emptyObservableList()
返回一个不可修改的空 ObservableList
,这就是您在调用 add< 时得到
.UnsupportedOperationException
的原因
改为使用 FXCollections.observableArrayList()
创建列表:
ObservableList<QuestionModel> qo = FXCollections.observableArrayList();
这将创建一个可以修改的列表。此列表最初为空。
关于java.lang.UnsupportedOperationException JavaFX ArrayList<String> 到 ObservableList<StringProperty>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41152073/
我有一个有趣的问题,我是 JavaFX 的新手,我需要创建一个小众市场 ObservableList执行。 本质上,我需要一个 ObservableList维护另一个 ObservableList 的
如果我有两个单独的 ObservableLists,并且都放在一个单独的 ObservableList 中用于 TableView...有没有办法在这两个 ObservableLists 和聚合的 O
当我尝试将项目设置到 tableView 中时遇到问题,有关我使用 SceneBuilder 的信息。 Main.java: public class Main extends Application
我想知道为什么TableView方法setItems不需要ObservableList作为参数,但是 ObservableList ? 还有什么是最好的转型方式ObservableList至Obser
当我将监听器附加到可观察列表并在该监听器中尝试删除一些元素时,在某些情况下它会通过,而在某些情况下会崩溃。 场景:项目已从列表中删除。它触发监听器,在该监听器中我尝试删除另一个项目。 如果在监听器中我
我在不同的条件下尝试了不同的集合,但我能够收到的所有更改都是排列、添加、删除和替换更改。 更新变化在什么条件下出现?什么基类,什么存储类以及需要什么操作来产生这样的事件? 最佳答案 要生成更新事件,您
This answer为可观察列表提供解决方案,如果列表元素的属性更改,它将发送“列表已更新” 通知>. 在我的例子中,此类可观察列表的元素(元素类)很复杂,我不喜欢为每个成员变量实现属性。因此,我在
这是我的问题:我有一堂 Detenu 课: public class Detenu { private static String n_ecrou; // Unique id p
我正在使用 JavaFX 编写日志读取器应用程序,并且我想根据所选属性实现基于搜索的过滤。 Application screenshot组合框中的值表示填充表的对象字段的名称。现在,我只想显示属性包含
给出以下代码示例: private final ObservableList data = FXCollections.observableArrayList( new Per
我有一个使用 JavaFX 的应用程序。它包含一个ListView(它使用ObservableList)。我使用添加了一个 ChangeListener list.getSelectionModel(
我有一个可观察列表,我尝试通过不同的谓词来过滤它。 我有要进行过滤的嵌套对象。 这是第一个 pojo public Class Transaction { private String na
例如,如果您有一个ArrayList,您可以执行以下操作: ArrayList list = new ArrayList(); ObservableList data = FXCollections.
我不太确定如何表达这个问题,请耐心等待。 我有一个 ObservableList用户定义的对象与几个 getter 方法,例如: public String getName() { return th
编辑 事实证明,当我实际上想要一个深拷贝时,FXCollections.observableArrayList() 正在创建列表的浅拷贝。 this.value 和 value “指向”两个不同的 O
我正在处理一个 javaFx 项目,我们必须在其中使用 ObservableList 添加 Listner。 ObservableList 包含人的模型。但是我想通过序列化将整个 Observable
我有一个自定义对象 FermentableInRecipe,它填充了一个 TableView。为了响应列表中项目的更改以及列表本身,我决定使用提取器。这是我的 ObservableList 的声明和实
我试图理解 ObservableList 和 Realms 的概念。我试图创建一个 ObservableList 的实例,如下所示: public ObservableList createObs
我有一个 Java ObservableList有数千个条目每秒接收数百个更新支持 JavaFX TableView . ObservableList 是 backed by an ArrayList
我有一张 Albums 的表格可由用户过滤和排序。 这是这张 table 的样子。如您所见,列是可排序的,顶部有一个文本框,当前正在过滤其中包含字符串“cu”的专辑: 一切正常专辑列表填充后 . 但是
我是一名优秀的程序员,十分优秀!