Все работало, но потом я попробовал создать .jar, он не запускался. В попытках вернуть все к прежнему, я окончательно потерялся.
Выдает следующую ошибку:
/usr/lib/jvm/java-12-oracle/bin/java --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED -Djava.library.path=/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib "-javaagent:/home/andriy/Java/IntelliJ IDEA/lib/idea_rt.jar=44303:/home/andriy/Java/IntelliJ IDEA/bin" -Dfile.encoding=UTF-8 -classpath /home/andriy/IdeaProjects/Calculator/out/production/Calculator:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/src.zip:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx-swt.jar:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.web.jar:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.base.jar:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.fxml.jar:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.media.jar:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.swing.jar:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.controls.jar:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.graphics.jar -p /home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.base.jar:/home/andriy/Java/openjfx-11.0.2_linux-x64_bin-sdk/javafx-sdk-11.0.2/lib/javafx.graphics.jar sample.Main
(java:17017): Gtk-WARNING **: 19:03:47.568: Theme parsing error: gtk-widgets.css:238:26: Missing closing bracket for :not()
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x7398fc4) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x7398fc4
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at sample.Main.start(Main.java:13)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Exception running application sample.Main
Process finished with exit code 1
Код програмы прилагается:
Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("fxml/sample.fxml"));
primaryStage.setTitle("Calculator");
primaryStage.setScene(new Scene(root, 235, 300));
primaryStage.setResizable(false);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Controller.java
package sample;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class Controller {
@FXML
private Label labelField;
@FXML
private Button clr_btn;
@FXML
private Button plusminus_btn;
@FXML
private Button perc_btn;
@FXML
private Button plus_btn;
@FXML
private Button button_7;
@FXML
private Button button_8;
@FXML
private Button button_9;
@FXML
private Button mult_btn;
@FXML
private Button button_4;
@FXML
private Button button_5;
@FXML
private Button button_6;
@FXML
private Button minus_btn;
@FXML
private Button button_1;
@FXML
private Button button_2;
@FXML
private Button button_3;
@FXML
private Button comma_btn;
@FXML
private Button equal_btn;
@FXML
private Button div_btn;
@FXML
private Button button_0;
private String str = "";
private double firstNum = 0;
private double secondNum = 0;
private double result = 0;
private char operation;
@FXML
void initialize(){
comma_btn.setOnAction(event -> {
if (!str.contains(".")) {
if(str == "") {
str = str + "0.";
}else{
str = str + ".";
}
labelField.setText(str);
}
});
clr_btn.setOnAction(event -> {
str = "";
labelField.setText("0");
});
equal_btn.setOnAction(event -> {
secondNum = Double.parseDouble(str);
switch (operation){
case '+':
result = firstNum + secondNum;
break;
case '-':
result = firstNum - secondNum;
break;
case '*':
result = firstNum * secondNum;
break;
case '/':
if(secondNum != 0) {
result = firstNum / secondNum;
} else {
result = 0;
}
break;
}
labelField.setText(String.valueOf(result));
str = String.valueOf(result);
});
plus_btn.setOnAction(event -> {
operation = '+';
firstNum = Double.parseDouble(str);
str = "";
labelField.setText("0");
});
minus_btn.setOnAction(event -> {
operation = '-';
firstNum = Double.parseDouble(str);
str = "";
labelField.setText("0");
});
mult_btn.setOnAction(event -> {
operation = '*';
firstNum = Double.parseDouble(str);
str = "";
labelField.setText("0");
});
div_btn.setOnAction(event -> {
operation = '/';
firstNum = Double.parseDouble(str);
str = "";
labelField.setText("0");
});
plusminus_btn.setOnAction(event -> {
double temp = Double.parseDouble(str);
temp = -1 * temp;
str = String.valueOf(temp);
labelField.setText(str);
});
perc_btn.setOnAction(event -> {
if (firstNum != 0){
secondNum = firstNum / 100 * Double.parseDouble(str);
switch (operation){
case '+':
result = firstNum + secondNum;
break;
case '-':
result = firstNum - secondNum;
break;
case '*':
result = firstNum * secondNum;
break;
case '/':
result = firstNum / secondNum;
break;
}
labelField.setText(String.valueOf(result));
str = String.valueOf(result);
}
});
button_0.setOnAction(event -> {
if(str != ""){
str = str + '0';
labelField.setText(str);
}
});
button_1.setOnAction(event -> {
str = str + '1';
labelField.setText(str);
});
button_2.setOnAction(event -> {
str = str + '2';
labelField.setText(str);
});
button_3.setOnAction(event -> {
str = str + '3';
labelField.setText(str);
});
button_4.setOnAction(event -> {
str = str + '4';
labelField.setText(str);
});
button_5.setOnAction(event -> {
str = str + '5';
labelField.setText(str);
});
button_6.setOnAction(event -> {
str = str + '6';
labelField.setText(str);
});
button_7.setOnAction(event -> {
str = str + '7';
labelField.setText(str);
});
button_8.setOnAction(event -> {
str = str + '8';
labelField.setText(str);
});
button_9.setOnAction(event -> {
str = str + '9';
labelField.setText(str);
});
}
}
sample.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="235.0" style="-fx-background-color: #363636;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<Label fx:id="labelField" alignment="CENTER_RIGHT" prefHeight="60.0" prefWidth="235.0" style="-fx-background-color: #363636; -fx-border-color: #363636; -fx-text-fill: #ffffff;" text="0" textAlignment="RIGHT" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<font>
<Font name="System Bold" size="36.0" />
</font>
</Label>
<GridPane layoutY="53.0" prefHeight="240.0" prefWidth="235.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="60.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="clr_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #e0e0e0; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="AC">
<font>
<Font name="System Bold" size="18.0" />
</font>
<cursor>
<Cursor fx:constant="DEFAULT" />
</cursor>
<opaqueInsets>
<Insets />
</opaqueInsets>
</Button>
<Button fx:id="plusminus_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #e0e0e0; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="+/-" GridPane.columnIndex="1">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="perc_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #e0e0e0; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="\%" GridPane.columnIndex="2">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="div_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #e3dc94; -fx-text-fill: #474747; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text=" ÷ " GridPane.columnIndex="3">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_7" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="7" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_8" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="8" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_9" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="9" GridPane.columnIndex="2" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="mult_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #e3dc94; -fx-text-fill: #474747; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="×" GridPane.columnIndex="3" GridPane.rowIndex="1">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_4" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="4" GridPane.rowIndex="2">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_5" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="5" GridPane.columnIndex="1" GridPane.rowIndex="2">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_6" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="6" GridPane.columnIndex="2" GridPane.rowIndex="2">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="minus_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #e3dc94; -fx-text-fill: #474747; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="-" GridPane.columnIndex="3" GridPane.rowIndex="2">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_1" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="1" GridPane.rowIndex="3">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_2" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="2" GridPane.columnIndex="1" GridPane.rowIndex="3">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_3" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="3" GridPane.columnIndex="2" GridPane.rowIndex="3">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="comma_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="," GridPane.columnIndex="2" GridPane.rowIndex="4">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="equal_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #e3dc94; -fx-text-fill: #474747; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="=" GridPane.columnIndex="3" GridPane.rowIndex="4">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="plus_btn" alignment="CENTER" maxHeight="48.0" maxWidth="58.75" mnemonicParsing="false" prefHeight="48.0" prefWidth="58.75" style="-fx-background-color: #e3dc94; -fx-text-fill: #474747; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="+" GridPane.columnIndex="3" GridPane.rowIndex="3">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
<Button fx:id="button_0" alignment="CENTER" maxHeight="48.0" maxWidth="119.5" mnemonicParsing="false" prefHeight="45.0" prefWidth="115.0" style="-fx-background-color: #999999; -fx-text-fill: #ffffff; -fx-border-color: #363636;" styleClass="btn" stylesheets="@../styles/style.css" text="0" GridPane.columnSpan="2" GridPane.rowIndex="4">
<font>
<Font name="System Bold" size="18.0" />
</font>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Button>
</children>
</GridPane>
</children>
</AnchorPane>
style.css
.btn:pressed{
-fx-background-color: #f5a742!important; }
Структура проекта:
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Почему литерал типа double (подходящий для float) не авто-преобразовывается в float? Но при этом, аналогичным образом, подходящий литерал int авто-преобразовывается...
не помогло and others didnt help? i work with phpmyAdmin? help me(другие случаи не работают) когда была локальная базаданных, все работало нормально, вот ссылка
Совсем новичок в Java, изучаю конструкторы и классыКак-бы встретилась проблема с выводом при "перезапуске" программы
Мне нужно вывести первый символ и проверить, чем он являетсяГде-то подсмотрел, что можно использовать str