我的getter/setter類的設定值如下:無法從一個getter/setter方法類
package cage;
public class hashtaggs {
private String a;
public String getHashtag()
{
return a;
}
public void setHashTag(String hashtag)
{
this.a=hashtag;
System.out.println(a);
}
}
GET方法使用的這個類
public class SaMain extends Application
{
public static void main(String []args) throws IOException
{
launch(args);
hashtaggs h=new hashtaggs();
String xh=h.getHashtag();
System.out.println(xh);
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Just a program");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Text scenetitle = new Text("Choose Your Input Method");
scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 15));
grid.add(scenetitle,1,0,3,1);
Button tbtn = new Button();
tbtn.setText(" Click here for input 1");
tbtn.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
try
{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Input1.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root1, 640, 480));
stage.show();
((Node)(event.getSource())).getScene().getWindow().hide();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
Button sbtn = new Button();
sbtn.setText(" Click here to input 2");
sbtn.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
try
{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Input2.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root1,640,480));
stage.show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
StackPane troot = new StackPane();
troot.getChildren().add(tbtn);
StackPane sroot = new StackPane();
sroot.getChildren().add(sbtn);
grid.add(troot, 1, 4,3,1);
grid.add(sroot, 1, 5,3,1);
Scene scene = new Scene(grid, 640, 480);
primaryStage.setScene(scene);
primaryStage.show();
}
}
的System.out.println(a)
打印出字符串,但我無法獲得當我使用getHashtag()
返回爲空的字符串的值。我從javafx ui條目的控制器中獲取字符串值。在使用get方法之前,我已使用launch(args);
。可能是什麼問題呢?
通過這個代碼不容易理解的問題。您需要更多地解釋併發布完整的代碼。 –
你確定,你在調用'setHashTag'後調用'getHastTag'? –
請分享代碼 – Lathy