2014-06-27 4 views
-3

pendant le travail sur mon projet a rencontré un problème.javafx erreur dans string.equals()

i ont ajouté un élément dans combobox:

@FXML 
private ComboBox schedule; 

j'avais ajouté une valeur

schedule.getItems().add("Create a new Schedule"); 

maintenant je compare la valeur:

 String p= (String) schedule.getSelectionModel().getSelectedItem(); 

    System.out.println(p); 
    if(p.equals("Create a new Schedule")){ 
    System.out.println("got it); 
    } 

Je reçois une erreur en ligne

 if(p.equals("Create a new Schedule")){ 

erreur:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1768) 
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1651) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
null 
    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.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:204) 
    at javafx.scene.Node.fireEvent(Node.java:8175) 
    at javafx.scene.control.ComboBoxBase.valueInvalidated(ComboBoxBase.java:136) 
    at javafx.scene.control.ComboBoxBase$2.invalidated(ComboBoxBase.java:161) 
    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:111) 
    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:145) 
    at javafx.scene.control.ComboBoxBase.setValue(ComboBoxBase.java:167) 
    at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin.setTextFromTextFieldIntoComboBoxValue(ComboBoxListViewSkin.java:512) 
    at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin.access$200(ComboBoxListViewSkin.java:57) 
    at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$6.changed(ComboBoxListViewSkin.java:416) 
    at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$6.changed(ComboBoxListViewSkin.java:406) 
    at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:347) 
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80) 
    at javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(ReadOnlyBooleanPropertyBase.java:72) 
    at javafx.scene.Node$FocusedProperty.notifyListeners(Node.java:7486) 
    at javafx.scene.Node.setFocused(Node.java:7537) 
    at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$FakeFocusTextField.setFakeFocus(ComboBoxListViewSkin.java:697) 
    at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$2.changed(ComboBoxListViewSkin.java:145) 
    at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$2.changed(ComboBoxListViewSkin.java:141) 
    at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:347) 
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80) 
    at javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(ReadOnlyBooleanPropertyBase.java:72) 
    at javafx.scene.Node$FocusedProperty.notifyListeners(Node.java:7486) 
    at javafx.scene.Node.setFocused(Node.java:7537) 
    at javafx.scene.Scene$KeyHandler.setWindowFocused(Scene.java:3918) 
    at javafx.scene.Scene$KeyHandler$1.invalidated(Scene.java:3937) 
    at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:135) 
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80) 
    at javafx.beans.property.ReadOnlyBooleanWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:178) 
    at javafx.beans.property.ReadOnlyBooleanWrapper$ReadOnlyPropertyImpl.access$100(ReadOnlyBooleanWrapper.java:148) 
    at javafx.beans.property.ReadOnlyBooleanWrapper.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:144) 
    at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110) 
    at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:143) 
    at javafx.stage.Window.setFocused(Window.java:409) 
    at com.sun.javafx.stage.WindowPeerListener.changedFocused(WindowPeerListener.java:59) 
    at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:89) 
    at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:39) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:130) 
    at com.sun.glass.ui.Window.handleWindowEvent(Window.java:1235) 
    at com.sun.glass.ui.Window.notifyFocus(Window.java:1210) 
    at com.sun.glass.ui.win.WinWindow._setVisible(Native Method) 
    at com.sun.glass.ui.Window.setVisible(Window.java:570) 
    at com.sun.javafx.tk.quantum.WindowStage.setVisible(WindowStage.java:455) 
    at javafx.stage.Window$9.invalidated(Window.java:776) 
    at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109) 
    at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:143) 
    at javafx.stage.Window.setShowing(Window.java:826) 
    at javafx.stage.Window.hide(Window.java:851) 
    at javafx.stage.Stage.close(Stage.java:1176) 
    at schoolmanagement2.DashboardController.close(DashboardController.java:213) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1763) 
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1651) 
    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.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:204) 
    at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3456) 
    at javafx.scene.Scene$ClickGenerator.access$8300(Scene.java:3387) 
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3755) 
    at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471) 
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695) 
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345) 
    at com.sun.glass.ui.View.handleMouseEvent(View.java:526) 
    at com.sun.glass.ui.View.notifyMouse(View.java:898) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39) 
    at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1763) 
    ... 110 more 
Caused by: java.lang.NullPointerException 
    at schoolmanagement2.ScheduleController.schedule(ScheduleController.java:462) 

Aidez-moi. incapable de trouver pourquoi j'ai eu cette erreur.

+0

Quelle est l'erreur? –

+0

J'ai mis à jour les codes – user3749316

+0

Stacktrace s'il vous plaît! 'Je reçois erreur sur la ligne' ok .. mais quelle est l'erreur? – RossC

Répondre

1

De la doc de SelectionModel « s, selectedItem porperty:

The selected item is either null, to represent that there is no selection, or [...]

Vous pouvez corriger votre code en changeant la piqûre constante avec p:

if("Create a new Schedule".equals(p)){