Exception ... MyClass is not a subclass of javafx.application.Application
1010688May 23 2013 — edited May 23 2013h2.Hi,
I am creating a Java based Framework, with it proper components that i create based on Java FX, so I know that every Class that uses JavaFx should extends "Application", the problem is that this class already extends from another one to verify the Class Diagram consistency "public class ZCPageDesktop extends ZCAbstractPage", now ZCPageDesktop should also extends "Application" to meet with Java FX specification but Multiple extends are not permitted in Java, So what i did is that i Created a Class Member called "private ZCFXApplication fxapp" which is an instance of the class ZCFXApplication that i created and extends "Application", so i redefined the method public void start(Stage primaryStage){/} then i created also another method to simulate the method public static void draw(String []args){ launch(args) // calling launch } all of this is done in my framework implementation, but when i go to the test , called "UserView" in the main i got this message " Exception in thread "main" java.lang.RuntimeException: Error: class org.zerocouplage.component.test.view.UserView is not a subclass of javafx.application.Application
at javafx.application.Application.launch(Application.java:211
at org.zerocouplage.component.test.view.UserView.main(UserView.java:57)"
How do i can fix this problem in a way that ZCPageDesktop extends Application, all in respecting the Java FX specification and the non permitted multiple extends ?
// Test Class
package org.zerocouplage.component.test.view;
import static org.zerocouplage.component.common.ZCComponentFactory.newComponent;
import java.io.IOException;
import org.zerocouplage.component.api.component.ZCButton;
import org.zerocouplage.component.api.component.ZCCheckBox;
import org.zerocouplage.component.api.component.ZCLabel;
import org.zerocouplage.component.api.component.ZCTextField;
import org.zerocouplage.component.api.layout.ZCBorderLayout;
import org.zerocouplage.component.api.page.ZCPage;
import org.zerocouplage.component.common.exception.ZCCompNotFoundException;
import org.zerocouplage.component.impl.component.ZCAbstractLabel;
import com.zerocouplage.api.controller.IZCManager;
import com.zerocouplage.common.exceptions.ZCExceptionConfig;
import com.zerocouplage.impl.controller.ZCManagerFactory;
import org.zerocouplage.component.desktop.page.ZCFXApplication;
*public class UserView {*
* @SuppressWarnings("unused")*
* private IZCManager manager;*
* public UserView() {*
* manager = ZCManagerFactory.getNewManager(this);*
* }*
* public Object createGui() throws IOException, ZCCompNotFoundException, ZCExceptionConfig {*
* ZCPage page = (ZCPage) newComponent(ZCPage.class);*
* page.setTitle("Page login");*
* ZCBorderLayout layout = (ZCBorderLayout) newComponent(ZCBorderLayout.class);*
* ZCAbstractLabel label = (ZCAbstractLabel) newComponent(ZCLabel.class);*
* label.setLabel("Nom");*
* ZCTextField textField = (ZCTextField) newComponent(ZCTextField.class);*
* textField.setText("Text");*
* ZCButton button = (ZCButton) newComponent(ZCButton.class);*
* button.setText("OK");*
* layout.setComponentCenter(button);*
* *
* *
* page.setBody(layout);*
* return page.display();*
* }*
*
* public static void main(String[] args) {*
* UserView userView = new UserView();*
* ZCFXApplication Fpage;*
* try {*
* Fpage=(ZCFXApplication)userView.createGui();*
* Fpage.launch(args);*
* } catch (IOException | ZCCompNotFoundException | ZCExceptionConfig e) {*
* e.printStackTrace();*
* }*
* }*
*}*
// the implementation of my API the class defining the consistency of the class diagram
package org.zerocouplage.component.desktop.page;
import org.zerocouplage.component.impl.page.ZCAbstractPage;
public class ZCPageDesktop extends ZCAbstractPage {
/**
* @author Taoufik RIFAI
*/
private ZCFXApplication fxapp;
public ZCPageDesktop() throws Exception {
this.setFxapp(new ZCFXApplication());
}
public Object display() {
fxapp.setTitle(this.getTitle());
fxapp.setLayout(this.getBody().display());
return fxapp;
// seul difference c'est que il faut que dans le test faire
// f.launch(String[] args) dans le main
}
public ZCFXApplication getFxapp() { return fxapp;}
public void setFxapp(ZCFXApplication fxapp) { this.fxapp = fxapp;}
}
// the class which extends Application defining the JavaFX specification
package org.zerocouplage.component.desktop.page;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.stage.Stage;
*public class ZCFXApplication extends Application {*
* /***
* * @author Taoufik RIFAI*
* */*
* private String title;*
* private Object layout;*
* public void start(Stage stage) throws Exception {*
* Group group = new Group();*
* group.getChildren().add((Node) getLayout());*
* System.out.println(getTitle());*
* if(getTitle()!=null){*
* stage.setTitle(getTitle());*
* }*
* *
* stage.setScene(new Scene(group, 300, 250));*
* stage.show();*
* }*
* public static void draw(String[] argument) {*
* launch(argument);*
* }*
* public Object getLayout() { return layout;}*
* public void setLayout(Object layout) { this.layout = layout; }*
* public String getTitle() {return title;}*
* public void setTitle(String title) {this.title = title; }*
*}*