0
我有一个关于从一个类传递对象属性到另一个的问题。我有两个类:AggiungiEs
这是一个JFrame界面,我可以通过三个纱厂选择值,并将其赋值给变量,从一个类传递对象属性到另一个类的方法
String serie = String.valueOf(spinner.getValue());
String ripetizioni = String.valueOf(spinner_1.getValue());
String recupero = String.valueOf(spinner_2.getValue());
然后我想创建这些变量的对象,这个对象传递给第二类方法是addEsercizioScheda
。
GestoreEsercizi gE = new GestoreEsercizi();
EsercizioScheda esercizio = new EsercizioScheda(nomeEs, gruppoMuscolare,
allenamento, serie, ripetizioni, recupero);
gE.addEsercizioScheda(esercizio, idScheda);
的问题是,他们的价值没有出现在第二类:当我打印出来它返回我“空” ......
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
它返回我“ null“...我该如何解决它?
你确定将String.valueOf(....)返回你所期望的正确的价值? – Alessio