Afterburner.fx — Файл: *.fxml не найденJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Afterburner.fx — Файл: *.fxml не найден

Сообщение Anonymous »

Я создаю простое приложение с помощью JavaFX + Afterburner.fx.
При запуске mvn clean javafx:run я получаю следующую ошибку:

Код: Выделить всё

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
...
Я дважды проверил, и мой RecipeListPresenter.fxml находится в target/:

Код: Выделить всё

-rw-rw-r-- 1 amaury amaury 291 janv.  11 21:23 RecipeListPresenter.fxml
Вот мой Main.java:

Код: Выделить всё

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);
}
}

У меня также есть FXMLView.java:

Код: Выделить всё

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);
}
}
}

А вот RecipeListPresenter.java:

Код: Выделить всё

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();
}
}
Структура каталогов:

Код: Выделить всё

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

Я понимаю, что файл загружается не из того места, но понятия не имею, как это сделать:
  • Проверьте место загрузки.
  • Измените его в соответствии со своими потребностями.


Подробнее здесь: https://stackoverflow.com/questions/793 ... -not-found
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»