因此,我正在制作此Lending Library程序,除删除列表视图中的最后一个项目外,其他所有内容似乎都可以正常工作,我已经查看了大约3个小时,无法弄清楚!由于某种原因,它仅在我删除最后一个项目时才执行。请帮助,这是我的代码。
LendingLibraryGUI
import java.io.IOException;
import javafx.application.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class LendingLibraryGUI extends Application {
LendingLibrary LendingLibrary = new LendingLibrary(); //Creating an Object to access total numbers of items
MediaItems Media = new MediaItems(); // creating an array of object to access MediaItems class and allowing it to hold 100 items
private ListView<String> library = new ListView<String>(); //Creates Listview
ObservableList<String> libraryList = FXCollections.<String>observableArrayList(); //Creates a list to use in the Listview
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane display = new BorderPane(); //Main display
GridPane buttons = new GridPane(); //location to display buttons
TextField outPut = new TextField(); //Text field to show inventory
Insets padding = new Insets(10); //creates Insets for padding
buttons.setPadding(padding); //padding around grid pane
buttons.setHgap(10); //Horizontal gap
libraryList = LendingLibrary.load(); //Loads contents from a txt file back into the listview
library.setItems(libraryList); //inputs list of data into the listview
for (int i =0; i !=4;i++) { //Loop to create Buttons
String[] actionButtons = {"Add","Check Out","Check In","Delete"};//String to store Button names
Button temp = new Button(actionButtons[i]); //creates a temp button
temp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); //sets the size of buttons
buttons.add(temp, i, 0); //add buttons to grid pane
GridPane.setHgrow(temp, Priority.ALWAYS);
GridPane.setVgrow(temp, Priority.ALWAYS);
if (temp.getText().equals("Add")) { //if add button is pushed
temp.setOnAction((e) -> {
try {
add();
} catch (IOException e1) {
e1.printStackTrace();
}
});
}
else if (temp.getText().equals("Delete")) { //if delete button is pushed
library.getSelectionModel().selectedItemProperty().addListener(ov -> { //gets the selected item from the listview
temp.setOnAction((e) -> {
if(libraryList.isEmpty()) {
}
else {
try {
deleteLibrary();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
});
}
else if (temp.getText().equals("Check Out")){ //if check out button is pushed
library.getSelectionModel().selectedItemProperty().addListener(ov -> { //gets the selected item from the listview
String name = library.getSelectionModel().getSelectedItem().toString(); //stores selected listview data into a string
temp.setOnAction((e) -> { { // when checkout button is pushed
if (name.contains(" is currently on loaned to ")) {
errorMessage("Currently on Loan");
}
else {
inputGUI("Who did you loan this to?");
}
}
});
});
}
else if (temp.getText().equals("Check In")) {
library.getSelectionModel().selectedItemProperty().addListener(ov -> { //gets the selected item from the listview
String name = library.getSelectionModel().getSelectedItem().toString(); //stores selected listview data into a string
temp.setOnAction((e) -> { { // when checkout button is pushed
if (!name.contains(" is currently on loaned to ")) { //Catch if the item is not on loan
errorMessage("Not on Loan");
}
else {
try {
checkIn();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
});
});
}
}
outPut.setEditable(false); //no editing
outPut.setFont(Font.font("monospace", FontWeight.BOLD, 20)); //sets fonts
outPut.setMinHeight(300);//sets minimum height
display.setTop(library); //sets output in display on top
display.setCenter(buttons); //sets buttons on center
Scene scene = new Scene(display); //creates new scene
primaryStage.setTitle("Lending Library"); //sets title of GUI
primaryStage.setScene(scene); //adds scene to GUI
primaryStage.setMinHeight(500); //Minimum height
primaryStage.setMinWidth(400);//Minimum Width
primaryStage.show();//Displays GUI to user
}
public static void main(String[] args) {
launch(args);
}
private void add() throws IOException { //adding items to the library
inputGUI("Title:"); //input method
try {
LendingLibrary.Save(library); //updates save of media
} catch (IOException e1) {
e1.printStackTrace();
}
}
private void inputGUI(String input) { //input method to put information into the list
Stage secondaryStage = new Stage();
BorderPane border = new BorderPane();
VBox titlePane = new VBox(8);
HBox buttonLayout = new HBox(8);
Label lblTitle = new Label(input);
Button save = new Button("Save");
Button close = new Button("Close");
Insets padding = new Insets(10);
TextField txt = new TextField("");
close.setOnAction((e) -> secondaryStage.close());; //close button closes secondary stage
save.setOnAction(new EventHandler<ActionEvent>() { //Save button to save information
@Override
public void handle(ActionEvent e) {
if (txt.getText().trim().isEmpty()) { //if text field is empty do nothing
errorMessage("Please Enter Data into the text area"); //tells user to enter data in text field
}
else {
if (input.equals("Title:")) { //gets the title of media
Media.setTitle(txt.getText()); //sets title of media
secondaryStage.close();
inputGUI("Format:"); //calls inputGUI to get format of media
}
else if (input.equals("Format:")) { //gets the format of media
Media.setFormat(txt.getText()); //sets format of media
secondaryStage.close();
addToLibrary(); //adds media to library
}
else if (input.equals("Who did you loan this to?")) { //gets information on who borrowed the media
Media.setLoan(txt.getText()); //sets loaned out
secondaryStage.close();
inputGUI("When did you loan it(date)?"); //gets date when media was borrowed
}
else if (input.equals("When did you loan it(date)?")) { //gets date when media was borrowed
Media.setDate(txt.getText());//sets date when media was borrowed
secondaryStage.close();
checkOut(); //checks out media from library
}
}
try {
LendingLibrary.Save(library); //updates save of media
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
buttonLayout.getChildren().addAll(close,save);
titlePane.setPadding(padding);
titlePane.getChildren().addAll(lblTitle,txt,buttonLayout);
border.setCenter(titlePane);
BorderPane.setAlignment(titlePane, Pos.CENTER);
Scene scene = new Scene(border); //creates new scene
secondaryStage.setTitle("Input"); //sets title of GUI
secondaryStage.setScene(scene); //adds scene to GUI
secondaryStage.setMinHeight(200); //Minimum height
secondaryStage.setMinWidth(350);//Minimum Width
secondaryStage.setMaxHeight(200); //Minimum height
secondaryStage.setMaxWidth(350);//Minimum Width
secondaryStage.show();//Displays GUI to user
}
private void addToLibrary() { //adding media to library
String total; //string to hold name and format of media
total = Media.getTitle();
total = total + " ("+ Media.getFormat() +")";
libraryList.add(total); //adds media to list
library.setItems(libraryList); //adds list to library
}
private void deleteLibrary() throws IOException { //deletes media from library
int selectedItem = library.getSelectionModel().getSelectedIndex(); //gets selected item in library list
libraryList.remove(selectedItem); //removes media from list
LendingLibrary.Save(library); //updates save of media
}
private void checkOut(){ //checkout method for media
String name = library.getSelectionModel().getSelectedItem().toString(); //grabs name of media selected
int selectedItem = library.getSelectionModel().getSelectedIndex(); //grabs location of media in list
libraryList.remove(selectedItem); //removes selected media
libraryList.add(name + " | is currently on loaned to " + Media.getLoan() + " on " + Media.getDate()); //add media back to list
}
private void checkIn() throws IOException { //check in method for media
String temp = library.getSelectionModel().getSelectedItem().toString(); //grabs name of media selected
String data = temp.substring(temp.indexOf("|") -1); //splits data up
temp = temp.replace(data, ""); //removes checked out
int selectedItem = library.getSelectionModel().getSelectedIndex(); //grabs location of media
libraryList.remove(selectedItem); //removes media
libraryList.add(temp); //adds data back in
try {
LendingLibrary.Save(library); //updates save of media
} catch (IOException e1) {
e1.printStackTrace();
}
}
private void errorMessage(String message) { //displays error messages
Stage errorStage = new Stage();
BorderPane border = new BorderPane();
VBox titlePane = new VBox(8);
HBox buttonLayout = new HBox(8);
Label lblTitle = new Label(message); //displays reason of error
Button close = new Button("Close");
Insets padding = new Insets(10);
close.setOnAction((e) -> errorStage.close());;
buttonLayout.getChildren().addAll(close);
buttonLayout.setAlignment(Pos.CENTER);
titlePane.setPadding(padding);
titlePane.getChildren().addAll(lblTitle,buttonLayout);
titlePane.setAlignment(Pos.CENTER);
border.setCenter(titlePane);
BorderPane.setAlignment(titlePane, Pos.CENTER);
Scene scene = new Scene(border); //creates new scene
errorStage.setTitle("Error"); //sets title of GUI
errorStage.setScene(scene); //adds scene to GUI
errorStage.setMinHeight(200); //Minimum height
errorStage.setMinWidth(350);//Minimum Width
errorStage.setMaxHeight(200); //Minimum height
errorStage.setMaxWidth(350);//Minimum Width
errorStage.show();//Displays GUI to user
}
}
LendingLibrary
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ListView;
public class LendingLibrary{
public void Save(ListView<String> library) throws IOException { //saves library as text file
String joined = library.getItems().stream()
.map(Object::toString)
.collect(Collectors.joining(", "));
File file = new File("LendingLibrary.txt");//Creates the text file Calc
file.createNewFile(); //if file doesnt exist it will create it (if it does nothing will happen)
if(file.exists()) { //if the file exists
PrintWriter output = new PrintWriter(file);
output.println(joined);
if(!file.exists()) { //if file doesn't exist
System.out.println("Error creating file");
}
output.close();
}
}
@SuppressWarnings("resource")
public ObservableList<String> load() throws FileNotFoundException { //loads information into program
ObservableList<String> libraryList = FXCollections.<String>observableArrayList(); //creates a list
File file = new File ("LendingLibrary.txt"); //access the file
if(file.exists()) { //if file does exist
Scanner input = new Scanner(file);
input.useDelimiter(","); //Separates data by a comma
while (input.hasNext()) { //while the list has data
String temp = input.next(); //stores data into a string
temp = temp.trim(); //trims spaces from beginning of data
if (temp.equals("")) {
}
else {
libraryList.addAll(temp); //stores data into the list
}
}
}
else if(!file.exists()) { //if does not file exist
}
return libraryList; //returns list to use in the listview
}
}
MediaItems
public class MediaItems {
private String title;
private String format;
private String loanedTo;
private String dateLoaned;
public void setTitle(String name) {title = name;}
public void setFormat(String type) {format = type;}
public String getTitle() {return title;}
public String getFormat() {return format;}
public void setLoan(String loaned) {loanedTo = loaned;}
public String getLoan() {return loanedTo; }
public void setDate(String date) {dateLoaned = date;}
public String getDate() {return dateLoaned;}
}
不确定是否重要,但这是它抛出的异常,它实际上并没有使程序崩溃,或者仅仅是我删除最后一个项目时抛出的错误...
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at LendingLibraryGUI.lambda$3(LendingLibraryGUI.java:85)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
at javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:102)
at javafx.scene.control.MultipleSelectionModelBase.lambda$new$34(MultipleSelectionModelBase.java:67)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyIntegerPropertyBase.fireValueChangedEvent(ReadOnlyIntegerPropertyBase.java:72)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:102)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:147)
at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:68)
at javafx.scene.control.MultipleSelectionModelBase.clearSelection(MultipleSelectionModelBase.java:682)
at javafx.scene.control.ListView$ListViewBitSetSelectionModel$2.onChanged(ListView.java:1222)
at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:183)
at LendingLibraryGUI.deleteLibrary(LendingLibraryGUI.java:266)
at LendingLibraryGUI.lambda$2(LendingLibraryGUI.java:72)
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.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.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.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
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.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:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
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$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at LendingLibraryGUI.lambda$5(LendingLibraryGUI.java:107)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
at javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:102)
at javafx.scene.control.MultipleSelectionModelBase.lambda$new$34(MultipleSelectionModelBase.java:67)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyIntegerPropertyBase.fireValueChangedEvent(ReadOnlyIntegerPropertyBase.java:72)
at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:102)
at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113)
at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:147)
at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:68)
at javafx.scene.control.MultipleSelectionModelBase.clearSelection(MultipleSelectionModelBase.java:682)
at javafx.scene.control.ListView$ListViewBitSetSelectionModel$2.onChanged(ListView.java:1222)
at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:183)
at LendingLibraryGUI.deleteLibrary(LendingLibraryGUI.java:266)
at LendingLibraryGUI.lambda$2(LendingLibraryGUI.java:72)
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.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.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.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
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.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:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
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$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
任何帮助将不胜感激!!预先感谢!
答案 0 :(得分:-1)
更改:
npm install <package> [options] .
收件人:
String name = library.getSelectionModel().getSelectedItem().toString();
library.getSelectionModel()。getSelectedItem()为null-即您正在取消引用null指针!