When I am running the below mentioned code it is working
import javafx.application.Application;
public class Client {
public static void main(String[] args){
Test t2 = new Test();
Application.launch(t2.getClass(),args);
}
}
where the test class is
package com.temp.com.serverclient;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Test extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("No Main");
StackPane root = new StackPane();
root.getChildren().add(new Label("It worked!"));
primaryStage.setScene(new Scene(root, 300, 120));
primaryStage.show();
}
}
But if I am trying to add constructor,it is getting Exception in Application constructor,Error. The code is
package com.temp.com.serverclient;
import javafx.application.Application;
public class Client {
public static void main(String[] args){
Test t1 = new Test("Pass this String to Constructor");
Application.launch(t1.getClass(),args);
}
}
Test class
package com.temp.com.serverclient;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Test extends Application {
String str;
public Test(String str) {
this.str = str;
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("No Main");
StackPane root = new StackPane();
root.getChildren().add(new Label("It worked!"));
primaryStage.setScene(new Scene(root, 300, 120));
primaryStage.show();
}
}
How Can I sovle the problem? I need to pass the String to collect information from previous class.