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