2013-03-17 13 views
6

में लिस्टप्रोपर्टी का उपयोग करके मैं उस सूची में एक वर्ग को परिभाषित करता हूं। मैं प्रेषित की सूची के साथ निर्माता में सूची प्रारंभ करने में कोशिश कर रहा हूँ:जावाएफएक्स

public class Person { 
    public IntegerProperty id; 
    public ListProperty<Priority> choice; 

    public Person(int id, List<Priority> list) { 
     this.id = new SimpleIntegerProperty(id); 
     this.choice = new SimpleListProperty<Priority>(); 
     for (int i = 0; i < 5; i++) { 
      this.choice.add(list.get(i)); 
     } 
    } 

    public IntegerProperty idProperty() { return id; } 
    public ListProperty<Priority> choiceProperty() { return choice; } 
} 

वर्ग Priority दो क्षेत्रों और उनके ही टिककर खेल में शामिल हैं:

public IntegerProperty rate; 
public StringProperty speciality; 

यह हो सकता है कि मैं ListProperty ठीक से उपयोग नहीं कर रहा?

जब मैं बनाने के लिए वस्तु का प्रयास करें:

Exception in Application start method 
Exception in thread "main" java.lang.RuntimeException: Exception in Application start  method 
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403) 
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47) 
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: java.lang.UnsupportedOperationException 
    at java.util.AbstractList.add(AbstractList.java:148) 
    at java.util.AbstractList.add(AbstractList.java:108) 
    at java.util.AbstractCollection.addAll(AbstractCollection.java:334) 
    at javafx.beans.binding.ListExpression.addAll(ListExpression.java:280) 
    at Person.setAllchoice(Person.java:24) 
    at Person.<init>(Person.java:17) 
    at Distribution.ReadDataFromFile(Distribution.java:85) 
    at Distribution.start(Distribution.java:28) 
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) 
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) 
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) 
    at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82) 
    ... 1 more 
+2

आपकी समस्या क्या है? – gontard

+0

जब मैं नई वस्तु बनाने की कोशिश करता हूं तो मुझे गलती मिलती है: "इसके कारण: java.lang.UnsupportedOperationException" – user1691070

+0

कृपया पूर्ण प्रश्न के साथ अपना प्रश्न पूरा करें। – gontard

उत्तर

14

इस तरह से SimpleListProperty प्रारंभ करने का प्रयास करें:

public Person(int id, List<Priority> list) { 
    ... 
    ObservableList<Priority> observableList = FXCollections.observableArrayList(list) 
    this.choice = new SimpleListProperty<Priority>(observableList); 
} 
+0

धन्यवाद, यह काम करता है! क्या मैं एक और सवाल पूछ सकता हूं - मैं इस सूची के सदस्य को पुनः प्राप्त करने का अनुमान कैसे लगा सकता हूं? उदाहरण के लिए आईडी को पुनर्प्राप्त करने के लिए मैं उपयोग करता हूं: सार्वजनिक इंटीजरप्रॉपर्टी आईडीप्रॉपर्टी() {वापसी आईडी; } – user1691070

+0

एक 'SimpleListProperty' एक' java.util.List' कार्यान्वयन है, इसलिए आप सदस्य को सामान्य रूप से पुनः प्राप्त कर सकते हैं। – gontard