How to fix UnsatisfiedLinkError? - java

I wish to use one of my local sound files to provide background music, but I get this error message:
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: C:\Program Files\Amazon Corretto\jdk1.8.0_232\jre\bin\glib-lite.dll
But my code is as follow:
public class DungeonGUI extends Application {
private Dungeon dungeon;
private Stage stage;
private GridPane root;
private Button attack;
private Button heal;
// private Button checkInventory;
private Button save;
private Text characterHealth;
private Text characterPower;
private Text characterInventory;
private Text monsterHealth;
private Text monsterPower;
private File audioFile = new File("C:/Users/15774/Downloads/oof.mp3");
#Override
public void start(Stage stage) throws Exception {
setButtons();
dungeon = new Dungeon();
setTexts();
this.stage = stage;
root = new GridPane();
heal.setOnAction(this::onHeal);
attack.setOnAction(this::onAttack);
save.setOnAction(this::onSave);
stage.setTitle("Dungeone Dungeon");
root.setAlignment(Pos.CENTER);
setMedia();
setupRoot();
setStage(stage);
}
private void setMedia() {
Media media = new Media(audioFile.toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
}
As you can see I did not call program files at any time. What might be the problem?
P.S.: this is only part of my code. If you guys need more information just shoot a comment.

Amazon Corretto for Java 8 does not support JavaFX. See here for full insight. However, as short, I refer to the following quote from the page:
The recommended way of using JavaFX is with Corretto 11 and pulling in OpenJFX separately e.g. with a Maven dependency. The latest version (currently 14) is compatible with Corretto 11.
src: Corretto's github
jccampanero also here answered a similar question.

Related

JavaFX image path for style

I'm currently trying to make a custom button using JavaFX. I have defined 2 styles that contain 2 different images for 2 button states(Pressed and Free). I'm using Intellij Idea and when defining the paths it shows no error's, but the button doesn't show up. Its just transparent, but I can click it. I have tried specified different paths, but haven't gotten any result. Here is the code where I define the styles and my file tree. Thanks!
public class CustomButton extends Button {
private final String FONT_PATH = "src/Resources/GUI/pixelFont.ttf";
private final String BUTTON_PRESSED_STYLE = "-fx-background-color: transparent;" +
" -fx-background-image: url('../../Resources/GUI/Buttondown.png');";
private final String BUTTON_FREE_STYLE = "-fx-background-color: transparent;" +
" -fx-background-image: url('../../Resources/GUI/Buttonup.png');";
public CustomButton(String text) {
setFont();
setPrefWidth(180);
setPrefHeight(53);
setText(text);
setStyle(BUTTON_PRESSED_STYLE);
initButtonListeners();
}
}
File tree
Moving all of the files into the pre-generated by Intellij Idea resources folder and then using that folder solved the issue.

Why does my program start in Eclipse but not as a jar file? [duplicate]

This question already has an answer here:
How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?
(1 answer)
Closed 2 years ago.
I have problem when trying to close current scene and open up another scene when menuItem is selected. My main stage is coded as below:
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Shop Management");
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("cartHomePage.fxml"));
Pane myPane = (Pane) myLoader.load();
CartHomePageUI controller = (CartHomePageUI) myLoader.getController();
controller.setPrevStage(primaryStage);
Scene myScene = new Scene(myPane);
primaryStage.setScene(myScene);
primaryStage.show();
}
When the program is executed, it will go to the cartHomePage.fxml. From there, I can select to go to create product or create category when the menu item is selected. Here is my action event:
Stage prevStage;
public void setPrevStage(Stage stage){
this.prevStage = stage;
}
public void gotoCreateCategory(ActionEvent event) throws IOException {
Stage stage = new Stage();
stage.setTitle("Shop Management");
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("createCategory.fxml"));
Pane myPane = (Pane) myLoader.load();
Scene scene = new Scene(myPane);
stage.setScene(scene);
prevStage.close();
setPrevStage(stage);
stage.show();
}
//Method to change scene when menu item create product is on click
#FXML
public void gotoCreateProduct(ActionEvent event) throws IOException {
Stage stage = new Stage();
stage.setTitle("Shop Management");
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("creatProduct.fxml"));
Pane myPane = (Pane) myLoader.load();
Scene scene = new Scene(myPane);
stage.setScene(scene);
prevStage.close();
setPrevStage(stage);
stage.show();
}
However, I can only switch the stage once. For example, my default page is cartHomePage.fxml. When I run the program, first I go to create product stage. After that, I cannot go to anywhere any more. The error message is:
java.lang.IllegalStateException: Location is not set.
and Null Pointer Exception
I did set the stage after I close it and pass it around. I wonder which part went wrong.
Thanks in advance.
I had this problem and found this post. My issue was just a file name issue.
FXMLLoader(getClass().getResource("/com/companyname/reports/" +
report.getClass().getCanonicalName().substring(18).replaceAll("Controller", "") +
".fxml"));
Parent root = (Parent) loader.load();
I have an xml that this is all coming from and I have made sure that my class is the same as the fxml file less the word controller.
I messed up the substring so the path was wrong...sure enough after I fixed the file name it worked.
To make a long story short I think that the problem is either the filename is named improperly or the path is wrong.
ADDITION:
I have since moved to a Maven Project. The non Maven way is to have everything inside of your project path. The Maven way which was listed in the answer below was a bit frustrating at the start but I made a change to my code as follows:
FXMLLoader loader = new FXMLLoader(ReportMenu.this.getClass().getResource("/fxml/" + report.getClass().getCanonicalName().substring(18).replaceAll("Controller", "") + ".fxml"));
I know this is a late answer, but I hope to help anyone else who has this problem. I was getting the same error, and found that I had to insert a / in front of my file path. The corrected function call would then be:
FXMLLoader myLoader = new FXMLLoader(getClass().getResource("/createCategory.fxml"));
// ^
I was getting this exception and the "solution" I found was through Netbeans IDE, simply:
Right-click -> "Clean and Build"
Run project again
I don't know WHY this worked, but it did!
I converted a simple NetBeans 8 Java FXML application to the Maven-driven one. Then I got problems, because the getResource() methods weren't able to find the .fxml files. In mine original application the fxmls were scattered through the package tree - each beside its controller class file.
After I made Clean and build in NetBeans, I checked the result .jar in the target folder - the .jar didn't contain any fxml at all. All the fxmls were strangely disappeared.
Then I put all fxmls into the resources/fxml folder and set the getResource method parameters accordingly, for example: FXMLLoader(App.class.getClassLoader().getResource("fxml/ObjOverview.fxml"));
In this case everything went OK. The fxml folder appeared int the .jar's root and it contained all my fxmls. The program was working as expected.
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../view/Main.fxml"));
in my case i just remove ..
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/Main.fxml"));
I've had the same issue in my JavaFX Application. Even more weird: In my Windows developement environment everything worked fine with the fxml loader. But when I executed the exact same code on my Debian maschine, I got similar errors with "location not set".
I read all answers here, but none seemed to really "solve" the problem. My solution was easy and I hope it helps some of you:
Maybe Java gets confused, by the getClass() method. If something runs in different threads or your class implements any interfaces, it may come to the point, that a different class than yours is returned by the getClass() method. In this case, your relative path to creatProduct.fxml will be wrong, because your "are" not in the path you think you are...
So to be on the save side: Be more specific and try use the static class field on your Class (Note the YourClassHere.class).
#FXML
public void gotoCreateProduct(ActionEvent event) throws IOException {
Stage stage = new Stage();
stage.setTitle("Shop Management");
FXMLLoader myLoader = new FXMLLoader(YourClassHere.class.getResource("creatProduct.fxml"));
Pane myPane = (Pane) myLoader.load();
Scene scene = new Scene(myPane);
stage.setScene(scene);
prevStage.close();
setPrevStage(stage);
stage.show();
}
After realizing this, I will ALWAYS do it like this. Hope that helps!
I tried a fast and simple thing:
I have two packages -> app.gui and app.login
In my login class I use the mainview.fxml from app.gui so I did this in the login.fxml
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../gui/MainView.fxml"));
And it works :)
This is often not getting the location path correct. It is important to realize that the path starts from the current package which the code resides in and not the root of the project. As long as you get this relative path correct, you should be able to steer clear of this error in this case.
I think problem is either incorrect layout name or invalid layout file path.
for IntelliJ, you can create resource directory and place layout files there.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/sample.fxml"));
rootLayout = loader.load();
I had the same problem.
after a few minutes, i figured it that i was trying the load the file.fxml from wrong location.
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/[wrong-path]/abc.fxml"));
fxmlLoader.setClassLoader(getClass().getClassLoader());
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
fxmlLoader.load();
The answer below by CsPeitch and others is on the right track. Just make sure that the fxml file is being copied over to your class output target, or the runtime will not see it. Check the generated class file directory and see if the fxml is there
For Intellij users, my issue was that the directory where I had my fxml files (src/main/resources), was not marked as a "Resources" directory.
Open up the module/project settings go to the sources tab and ensure that Intellij knows that the directory contains project resource files.
I mean something like this:
FXMLLoader myLoader = null; Scene myScene = null; Stage prevStage = null;
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Shop Management");
myLoader = new FXMLLoader(getClass().getResource("cartHomePage.fxml"));
Pane myPane = (Pane) myLoader.load();
CartHomePageUI controller = (CartHomePageUI) myLoader.getController();
controller.setPrevStage(primaryStage);
myScene = new Scene(myPane);
primaryStage.setScene(myScene);
primaryStage.show();
}
After that
public void setPrevStage(Stage stage){
this.prevStage = stage;
}
public void gotoCreateCategory(ActionEvent event) throws IOException {
Stage stage = new Stage();
stage.setTitle("Shop Management");
myLoader = new FXMLLoader(getClass().getResource("createCategory.fxml"));
Pane myPane = (Pane) myLoader.load();
Scene scene = new Scene(myPane);
stage.setScene(scene);
// prevStage.close(); I don't think you need this, closing it will set preStage to null put a breakpoint after this to confirm it
setPrevStage(stage);
stage.show();
}
//Method to change scene when menu item create product is on click
#FXML
public void gotoCreateProduct(ActionEvent event) throws IOException {
Stage stage = new Stage();
stage.setTitle("Shop Management");
myLoader = new FXMLLoader(getClass().getResource("creatProduct.fxml"));
Pane myPane = (Pane) myLoader.load();
Scene scene = new Scene(myPane);
stage.setScene(scene);
// prevStage.close(); I don't think you need this, closing it will set preStage to null put a breakpoint after this to confirm it
setPrevStage(stage);
stage.show();
}
Try it and let me know please.
That happened to me an i found the solution. If u build your project with your .fxml files in different packages from the class that has the launch line
(Parent root = FXMLLoader.load(getClass().getResource("filenamehere.fxml"));)
and use a relative path your windows except from the first one wont launch when your run the jar. To keep it short place the .fxml file in the same package with the class that launches it and set the path like this ("filenamehere.fxml") and it should work fine.
I've stumbled upon the same problem. Program was running great from Eclipse via "Run" button, but NOT from runnable JAR which I'd exported before.
My solution was:
1) Move Main class to default package
2) Set other path for Eclipse, and other while running from the JAR file
(paste this into Main.java)
public static final String sourcePath = isProgramRunnedFromJar() ? "src/" : "";
public static boolean isProgramRunnedFromJar() {
File x = getCurrentJarFileLocation();
if(x.getAbsolutePath().contains("target"+File.separator+"classes")){
return false;
} else {
return true;
}
}
public static File getCurrentJarFileLocation() {
try {
return new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
} catch(URISyntaxException e){
e.printStackTrace();
return null;
}
}
And after that in start method you have to load files like this:
FXMLLoader loader = new FXMLLoader(getClass().getResource(sourcePath +"MainScene.fxml"));
It works for me in Eclipse Mars with e(fx)clipse plugin.
mine was strange... IntelliJ specific quirk.
I looked at my output classes and there was a folder:
x.y.z
instead of
x/y/z
but if you have certain options set in IntelliJ, in the navigator they will both look like x.y.z
so check your output folder if you're scratching your head
I had the same problem. It's a simple problem of not specifying the right path.
Right click on the on your .fxml file and select properties (for those using eclipse won't differ that much for another IDE) and then copy the copy the location starting from /packagename till the end and that should solve the problem
I had the same problem, I changed the FXML name to the FXML file in the controller class and the problem was solved.
This worked for me well :
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/TestDataGenerator.fxml"));
loader.setClassLoader(getClass().getClassLoader());
Parent root = loader.load();
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
In my case the reason for the error was an runtime error in my corresponding java class. I fixed it and all was ok.
My tip: don't search for an "location not set"
I had faced he similar problem however it got resolved once i renamed the file , so i would suggest that you should
"Just rename the file"

RTL Support Using Vaadin 14

I trying to build web app in Hebrew.
but all of the components or Navbar are LTR.
how can I make my NavBar or all my site to be RTL?
onemore question can I change the style of the navbar?
#Viewport("width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes, viewport-fit=cover")
#Theme(Lumo.class)
#Route
#PWA(name = "SimpleIT", shortName = "SimpeIT")
public class MainView extends AppLayout {
public static final String ITM_DASHBOARD = "DashBoard";
private Map<Tab, Component> tab2Workspace = new HashMap<>();
public MainView() {
// setPrimarySection(Section.DRAWER);
Image img = new Image("https://i.imgur" +
".com/GPpnszs.png", "Vaadin Logo");
img.setHeight("75px");
addToNavbar(new MenuBar(), img);
Tabs menu = new Tabs(dashBoard()
,new Tab("Customers"),new Tab("Todo"),new Tab("Tickets"));
menu.setOrientation(Tabs.Orientation.HORIZONTAL);
menu.addSelectedChangeListener(event -> {
final Tab selectedTab = event.getSelectedTab();
final Component component = tab2Workspace.get(selectedTab);
setContent(component);
});
addToNavbar(menu);
this.setPrimarySection(Section.NAVBAR);
setContent(new Span("click in the menu ;-) , you will see me never again.."));
}
private Tab dashBoard() {
final Span label = new Span("DashBoard");
final Icon icon = DASHBOARD.create();
final Tab tab = new Tab(new HorizontalLayout(icon,label));
tab2Workspace.put(tab, new DashBoardView());
return tab;
}
}
You can turn RTL by adding the CSS rule direction:rtl to the body. Alternatively you can use the RTL mode add-on that does that for you: https://vaadin.com/directory/component/rtl-mode/discussions
Many of the component work in RTL mode, but some have still some issues. They will be hopefully fixed in the first half of 2020.
Updated information: RTL is officially supported since Vaadin 14.3 (LTS) and Vaadin 17: https://vaadin.com/blog/localization-gets-an-update-with-right-to-left-rtl-support

Using a pre-loaded icon

I'm using the following to show a cross in a label, that accompanies an if statement.
JLabel.setIcon(new ImageIcon(path + "Resource/cross.png"));
Instead of loading the icon everytime I would prefer to have it imported into my project and call it from there. I know how to import it but how do I modify the line of code above to point to the imported icon.
you can create a static loader methode (in an utility class) and store it there
private static Map<String, Icon> lookUpMap = new HashMap<>();
public static Icon getImageIcon(String res){
Icon icon = lookUpMap.get(res);
if(icon = null){
icon = new ImageIcon(res);
lookUpMap.put(res, icon);
}
return icon;
}
you can access the icons now everywhere
JLabel.setIcon(UtilitClass.getImageIcon(path + "Resource/cross.png));

GWT-AI Integration

I am developing a demo application with using GwtAI (Gwt Applet Integration). I have included all the GwtAI-client.jar,GwtAI-core.jar.I am referring to the http://code.google.com/p/gwtai/wiki/GettingStarted Following is the code.
FileUploadingApplet.class
#ImplementingClass(com.nextenders.appletImpl.FileUploadingAppletImpl.class)
#Height("60")
#Width("350")
#Archive("GwtAI-Client.jar,FileUploadingAppletImpl.jar")
#Codebase("applet")
public interface FileUploadingApplet extends Applet{
public void increment();
public void decrement();
public Object getCurrentValue();
}
FileUploadingAppletImpl.class
public class FileUploadingAppletImpl extends JApplet implements FileUploadingApplet {
JTextField m_fileNameTF = new JTextField(15);
String controlTransactionId = "";
JFileChooser m_fileChooser = new JFileChooser();
JPanel content = new JPanel();
FileWriter fstream = null;
long fileLength = 0l;
#Override
public void init() {
JPanel panelMain = new JPanel();
m_fileNameTF = new JTextField(20);
m_fileNameTF.setHorizontalAlignment(JTextField.CENTER);
m_fileNameTF.setText("0");
m_fileNameTF.setEditable(false);
panelMain.add(new JLabel("Current count : "));
panelMain.add(m_fileNameTF);
panelMain.setBorder(BorderFactory.createTitledBorder("CounterApplet"));
panelMain.setBackground(Color.WHITE);
getContentPane().add(panelMain);
}
public void increment() {
int currentCount = Integer.parseInt(m_fileNameTF.getText());
currentCount++;
m_fileNameTF.setText(currentCount + "");
}
public void decrement() {
int currentCount = Integer.parseInt(m_fileNameTF.getText());
currentCount--;
m_fileNameTF.setText(currentCount + "");
}
public Object getCurrentValue() {
return m_fileNameTF.getText();
}
}
NTFileUpload.java
private void createPanel(){
PopupPanel panel = new PopupPanel();
panel.setPopupPosition(500, 500);
panel.setHeight("600px");
panel.setHeight("900px");
final FileUploadingApplet fileUploadApplet = (FileUploadingApplet) GWT.create(FileUploadingApplet.class);
VerticalPanel panelMain = new VerticalPanel();
Button buttonInc = new Button("Increment");
buttonInc.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
fileUploadApplet.increment();
}
});
Widget widgetApplet = AppletJSUtil.createAppletWidget(fileUploadApplet);
panelMain.add(widgetApplet);
panelMain.add(buttonInc);
panel.add(panelMain);
panel.show();
}
I have followed the package structure as per the link. But I am getting following Exception.
java.lang.IncompatibleClassChangeError: Found interface com.google.gwt.core.ext.typeinfo.JClassType, but class was expected
at com.google.gwt.gwtai.applet.generator.AppletProxyGenerator.generate(AppletProxyGenerator.java:71)
at com.google.gwt.core.ext.GeneratorExtWrapper.generate(GeneratorExtWrapper.java:48)
at com.google.gwt.core.ext.GeneratorExtWrapper.generateIncrementally(GeneratorExtWrapper.java:60)
at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:647)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:78)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:268)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:257)
at com.google.gwt.dev.DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(DistillerRebindPermutationOracle.java:91)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:96)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.process(AbstractCompiler.java:254)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:173)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:288)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.access$400(AbstractCompiler.java:139)
at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:588)
at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:97)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:52)
at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:569)
at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:33)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:284)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:233)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:145)
at com.google.gwt.dev.Compiler.run(Compiler.java:232)
at com.google.gwt.dev.Compiler.run(Compiler.java:198)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
at com.google.gwt.dev.Compiler.main(Compiler.java:177)
Thanks in advance.
you need to build the dependencies that you're using (jar/war) with the same GWT SDK version that you are using for compilation of your project i.e. if 2.4 then use 2.4 to jar the dependencies and then compile your project. This error is due to the mismatch in the SDK versions being used.
There have been breaking changes in the GWT code generator feature, between version 1.7 and 2.0. So make sure you have the current version of GwtAI, if you work with a GWT version 2.0 or higher. If you work with a GWT version before 2.0 go to the GwtAI download page, select All downloads and click Search, you should see GwtAI 0.2 files. Those
should work with older GWT versions.

Categories

Resources