我的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