Java 将对象属性从一个类传递给另一个类的方法

Java 将对象属性从一个类传递给另一个类的方法,java,class,object,methods,jframe,Java,Class,Object,Methods,Jframe,我在将对象属性从一个类传递到另一个类时遇到了一个问题。我有两个类:AggiungiEs,它是一个jframe接口,我可以通过三个微调器选择值并将它们分配给变量 String serie = String.valueOf(spinner.getValue()); String ripetizioni = String.valueOf(spinner_1.getValue()); String recupero = String.valueOf(spinner_2.getValue()); 然后我

我在将对象属性从一个类传递到另一个类时遇到了一个问题。我有两个类:AggiungiEs,它是一个jframe接口,我可以通过三个微调器选择值并将它们分配给变量

String serie = String.valueOf(spinner.getValue());
String ripetizioni = String.valueOf(spinner_1.getValue());
String recupero = String.valueOf(spinner_2.getValue());
然后我想用这些变量创建一个对象,并将这个对象传递给第二个类方法addEsercizioScheda

问题是它们的值不会出现在第二个类中:当我打印它们时,它会返回null

public void addEsercizioScheda(EsercizioScheda esercizioScheda, String idScheda) {

        [.......SOME STUFF TO WRITE IN A XML FILE]

    Element IDEsercizio = ultimoElemento.getChild("ID");
    IDEsercizio.setText(UUID.randomUUID().toString());
    Element nodoEsercizi = new Element("Esercizi");
    ultimoElemento.addContent(nodoEsercizi);
    nodoEsercizi.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoEsercizioScheda = new Element("EsercizioScheda");
    nodoEsercizi.addContent(nodoEsercizioScheda);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoIDEsercizioScheda = new Element("ID").setText(UUID.randomUUID().toString());
    nodoEsercizioScheda.addContent(nodoIDEsercizioScheda);
    nodoEsercizioScheda.addContent("\n");
    Element nodoIDAllenamento = new Element("IDAllenamento").setText("DA MODIFICARE");
    nodoEsercizioScheda.addContent(nodoIDAllenamento);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoSerie = new Element("Serie").setText(esercizioScheda.serie);
    nodoEsercizioScheda.addContent(nodoSerie);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoRipetizioni = new Element("Ripetizioni").setText(esercizioScheda.ripetizioni);
    nodoEsercizioScheda.addContent(nodoRipetizioni);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoRecupero = new Element("Recupero").setText(esercizioScheda.recupero);
    nodoEsercizioScheda.addContent(nodoRecupero);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    System.out.println(esercizioScheda.serie);

            [....]

当我打印esercizioScheda.serie时,它返回空值。。。如何修复它?

我看不出您发送对象属性的方式有什么问题。您是否可以调试并检查serie属性返回的内容:


字符串serie=spinner.getValue.toString

你确定字符串.valueOf。。。。返回您期望的正确值?
public void addEsercizioScheda(EsercizioScheda esercizioScheda, String idScheda) {

        [.......SOME STUFF TO WRITE IN A XML FILE]

    Element IDEsercizio = ultimoElemento.getChild("ID");
    IDEsercizio.setText(UUID.randomUUID().toString());
    Element nodoEsercizi = new Element("Esercizi");
    ultimoElemento.addContent(nodoEsercizi);
    nodoEsercizi.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoEsercizioScheda = new Element("EsercizioScheda");
    nodoEsercizi.addContent(nodoEsercizioScheda);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoIDEsercizioScheda = new Element("ID").setText(UUID.randomUUID().toString());
    nodoEsercizioScheda.addContent(nodoIDEsercizioScheda);
    nodoEsercizioScheda.addContent("\n");
    Element nodoIDAllenamento = new Element("IDAllenamento").setText("DA MODIFICARE");
    nodoEsercizioScheda.addContent(nodoIDAllenamento);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoSerie = new Element("Serie").setText(esercizioScheda.serie);
    nodoEsercizioScheda.addContent(nodoSerie);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoRipetizioni = new Element("Ripetizioni").setText(esercizioScheda.ripetizioni);
    nodoEsercizioScheda.addContent(nodoRipetizioni);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    Element nodoRecupero = new Element("Recupero").setText(esercizioScheda.recupero);
    nodoEsercizioScheda.addContent(nodoRecupero);
    nodoEsercizioScheda.addContent("\n");         // va a capo ad ogni cambio di tag
    System.out.println(esercizioScheda.serie);

            [....]