Domanda Risolto JavaFX: Cosa sto sbagliando?

Stato
Discussione chiusa ad ulteriori risposte.

Fastidio

Utente Gold
1 Gennaio 2014
594
55
104
287
Buonasera,
Stavo scrivendo del codice quando mi sono imbattuto in questo errore e non sto capendo cosa sto sbagliando..
Mi segna l'errore sul metodo "showOverviewLayout" e dice questo "void is an invalid type for the variable showOverviewLayout".
Mi sta facendo diventare scemo..
Java:
package core;

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MainApp extends Application {

    private Stage primaryStage;
    private BorderPane rootLayout;

    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("InfoOS");
        
        initRootLayout();
        showOverviewLayout();
    }

    public static void main(String[] args) {
        launch(args);
    }

    // initialize the root layout

    public void initRootLayout() {
        try {
            //load
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("gui/RootLayout.fxml"));
            rootLayout = (BorderPane) loader.load();

            // Show the scene containing the root layout
            Scene scene = new Scene(rootLayout);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public void showOverviewLayout {
        try {
            //load
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("gui/OverviewLayout.fxml"));
            AnchorPane overview = (AnchorPane) loader.load();
            
            //Set the table into the center of root layout
            rootLayout.setCenter(overview);
        }catch (IOException e) {
            e.printStackTrace();
        }
        
    }
}
Mi dareste una mano a capire? Grazie.
 
Buonasera,
Stavo scrivendo del codice quando mi sono imbattuto in questo errore e non sto capendo cosa sto sbagliando..
Mi segna l'errore sul metodo "showOverviewLayout" e dice questo "void is an invalid type for the variable showOverviewLayout".
Mi sta facendo diventare scemo..
Java:
package core;

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MainApp extends Application {

    private Stage primaryStage;
    private BorderPane rootLayout;

    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("InfoOS");
       
        initRootLayout();
        showOverviewLayout();
    }

    public static void main(String[] args) {
        launch(args);
    }

    // initialize the root layout

    public void initRootLayout() {
        try {
            //load
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("gui/RootLayout.fxml"));
            rootLayout = (BorderPane) loader.load();

            // Show the scene containing the root layout
            Scene scene = new Scene(rootLayout);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
   
    public void showOverviewLayout {
        try {
            //load
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("gui/OverviewLayout.fxml"));
            AnchorPane overview = (AnchorPane) loader.load();
           
            //Set the table into the center of root layout
            rootLayout.setCenter(overview);
        }catch (IOException e) {
            e.printStackTrace();
        }
       
    }
}
Mi dareste una mano a capire? Grazie.
Codice:
 public void showOverviewLayout () {
 
 }
Non noti niente di strano?
 
  • Mi piace
Reazioni: 0xEHz e 0xbro
Buonasera,
Stavo scrivendo del codice quando mi sono imbattuto in questo errore e non sto capendo cosa sto sbagliando..
Mi segna l'errore sul metodo "showOverviewLayout" e dice questo "void is an invalid type for the variable showOverviewLayout".
Mi sta facendo diventare scemo..
Java:
package core;

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class MainApp extends Application {

    private Stage primaryStage;
    private BorderPane rootLayout;

    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("InfoOS");
       
        initRootLayout();
        showOverviewLayout();
    }

    public static void main(String[] args) {
        launch(args);
    }

    // initialize the root layout

    public void initRootLayout() {
        try {
            //load
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("gui/RootLayout.fxml"));
            rootLayout = (BorderPane) loader.load();

            // Show the scene containing the root layout
            Scene scene = new Scene(rootLayout);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
   
    public void showOverviewLayout {
        try {
            //load
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("gui/OverviewLayout.fxml"));
            AnchorPane overview = (AnchorPane) loader.load();
           
            //Set the table into the center of root layout
            rootLayout.setCenter(overview);
        }catch (IOException e) {
            e.printStackTrace();
        }
       
    }
}
Mi dareste una mano a capire? Grazie.
Mancano le parentesi alla funzione showOverviewLayout.
Anche l'errore stesso ti suggerisce cosa sta accadendo: la funzione, senza parentesi, è riconosciuta come variabile e di certo non puoi creare una variabile Void, non avrebbe alcun senso.
Fate attenzione agli errori, spesso sono loro stessi la soluzione.
 
Stato
Discussione chiusa ad ulteriori risposte.