Afterburner.fx – Datei: *.fxml nicht gefundenJava

Java-Forum
Guest
 Afterburner.fx – Datei: *.fxml nicht gefunden

Post by Guest »

Ich erstelle eine einfache Anwendung mit JavaFX + Afterburner.fx.
Beim Ausführen von mvn clean javafx:run erhalte ich diese Fehlermeldung:

Code: Select all

File: recipelistpresenter.fxml not found, attempting with camel case
Cannot load file RecipeListPresenter.fxml
Stopping initialization phase...
Exception in Application start method
java.lang.reflect.InvocationTargetException
...
Ich habe es noch einmal überprüft und meine RecipeListPresenter.fxml befindet sich im Ziel/:

Code: Select all

-rw-rw-r-- 1 amaury amaury 291 janv.  11 21:23 RecipeListPresenter.fxml
Hier ist meine Main.java:

Code: Select all

package com.example.eatti;

import com.airhacks.afterburner.injection.Injector;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import com.example.eatti.view.recipe.RecipeListPresenter;

public class Main extends Application {
@Override
public void start(Stage stage) {
RecipeListPresenter recipeListPresenter = new RecipeListPresenter();
Scene scene = new Scene(recipeListPresenter.getView());
stage.setTitle("Recipe Manager");
stage.setScene(scene);
stage.show();
}

@Override
public void stop() throws Exception {
Injector.forgetAll(); // Cleanup Afterburner.fx injections
}

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

Ich habe auch eine FXMLView.java:

Code: Select all

package com.example.eatti.view;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FXMLView {
private static final Logger log = LoggerFactory.getLogger(FXMLView.class);

public static void load(String fxmlPath, Stage stage) {
try {
log.debug("Loading FXML from path: {}", fxmlPath);
FXMLLoader loader = new FXMLLoader(FXMLView.class.getResource(fxmlPath));
Parent root = loader.load();
log.debug("FXML successfully loaded: {}", fxmlPath);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
} catch (Exception e) {
log.error("Error loading FXML file: {}", fxmlPath, e);
throw new RuntimeException(e);
}
}
}

Und hier ist die RecipeListPresenter.java:

Code: Select all

package com.example.eatti.view.recipe;

import javax.inject.Inject;
import com.airhacks.afterburner.views.FXMLView;
import com.example.eatti.model.entity.Recipe;
import com.example.eatti.service.RecipeService;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.UUID;

public class RecipeListPresenter extends FXMLView {
private static final Logger log = LoggerFactory.getLogger(RecipeListPresenter.class);

@Inject
private RecipeService recipeService;

@FXML
private ListView recipeListView;

@FXML
public void initialize() {
loadRecipes();
setupListView();
}

private void loadRecipes() {
List recipes = recipeService.findAllRecipes();
for (Recipe recipe : recipes) {
Pair recipeItem = new Pair(recipe.getId(), recipe.getName());
recipeListView.getItems().add(recipeItem);
}
}

private void setupListView() {
recipeListView.setCellFactory(param -> new ListCell() {
@Override
protected void updateItem(Pair item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
} else {
setText(item.getValue());
}
}
});
recipeListView.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) {
handleRecipeDoubleClick(event);
}
});
}

private void handleRecipeDoubleClick(MouseEvent event) {
if (event.getClickCount() == 2) {
Pair  selectedRecipe = recipeListView.getSelectionModel().getSelectedItem();
if (selectedRecipe != null) {
UUID selectedRecipeId = selectedRecipe.getKey();
Recipe recipe = recipeService.findRecipeById(selectedRecipeId);
if (recipe != null) {
openRecipeDetails(recipe);
}
}
}
}

private void openRecipeDetails(Recipe recipe) {
log.debug("Opening recipe: {}", recipe.getName());
Stage stage = new Stage();
RecipeDetailsPresenter recipeDetailsPresenter = new RecipeDetailsPresenter();
recipeDetailsPresenter.setRecipe(recipe);
stage.setScene(new Scene(recipeDetailsPresenter.getView()));
stage.show();
}
}
Verzeichnisstruktur:

Code: Select all

src/main/
├── java
│   └── com
│       └── example
│           └── eatti
│               ├── controller
│               ├── Main.java
│               ├── model
│               │   ├── entity
│               │   │   ├── Ingredient.java
│               │   │   ├── RecipeIngredient.java
│               │   │   ├── Recipe.java
│               │   │   ├── RecipeUnit.java
│               │   │   └── Unit.java
│               │   └── repository
│               │       ├── IngredientRepository.java
│               │       ├── RecipeIngredientRepository.java
│               │       ├── RecipeRepository.java
│               │       ├── RecipeUnitRepository.java
│               │       └── UnitRepository.java
│               ├── service
│               │   └── RecipeService.java
│               ├── util
│               │   └── HibernateUtil.java
│               └── view
│                   ├── FXMLView.java
│                   └── recipe
│                       ├── RecipeDetailsPresenter.java
│                       ├── RecipeFormPresenter.java
│                       └── RecipeListPresenter.java
└── resources
├── application.properties
├── com
│   └── example
│       └── eatti
│           └── fxml
│               ├── recipe-details.fxml
│               ├── recipe-form.fxml
│               └── RecipeListPresenter.fxml
└── hibernate.cfg.xml

18 directories, 22 files

Ich habe den Eindruck, dass die Datei nicht vom richtigen Ort geladen wurde, aber ich habe keine Ahnung, wie das geht:
  • Überprüfen Sie den Ladeort
  • Ändern Sie ihn entsprechend meinen Anforderungen

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post