Usually error message shows up when carsol is on the red "x" mark. But any message won't show up. What is this error?
I'm using:
Eclipse IDE for Enterprise Java Developers. Version: 2019-03 (4.11.0)
PostgreSQL
I will show CustomerController.java below
package application2;
import java.net.URL;
```
public class CustomerController implements Initializable {
@FXML
AnchorPane paneRoot; //SceneBuilderで作ったやつ,一度コメントアウトしたら
@FXML
Button button; //インポートし直す必要がある
@FXML
ComboBox<String> combo_Func;
@FXML
ComboBox<String> combo_Info;
@FXML
TextField textField1;
@FXML
TextField textField2;
@FXML
TextField textField3;
@FXML
TextField textField4;
@FXML
TextField textField5;
@FXML
Label label1;
@FXML
Label label2;
@FXML
Label label3;
@FXML
Label label4;
@FXML
Label label5;
// DataBase connection --------------
Connection conn = Customer.dbConf.getConn();
Statement stmt = null;
ResultSet rset = null;
```
// 1st method "Initialize"機能ボックスへの表示------
@Override
public void initialize(URL address, ResourceBundle rb) {
label1.setVisible(true);
```
}
// 2nd method "Show the list in the Ribbon" コンボボックスへの表示
public void comboSet() {
try {
// SELECT文の実行
stmt = conn.createStatement();
String sql = "SELECT customername, customercode, address, province FROM customer WHERE delrecflag = 0 ORDER BY customercode DESC"; //DESCを消せば昇順
rset = stmt.executeQuery(sql); //結果がなければnullを返却する
// SELECT結果の受け取り
bukenComboList.clear();
while (rset.next()) {
name = rset.getString("customername");
code = rset.getString("customercode");
bukenComboList.add(name " (" code ")");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
conn.commit();
rset.close();
rset = null;
stmt.close();
stmt = null;
} catch (SQLException e) {
e.printStackTrace();
Alert alrt = new Alert(AlertType.WARNING); // アラートを作成
alrt.setHeaderText("システムエラー");
alrt.setContentText("システムエラーが発生しました(comboSet())");
alrt.showAndWait(); // 表示する
}
}
}
// 3rd method "Select menu"combobox変更時の処理 ------------------------------------
@FXML
void chngFunc() {
String cmb_val = ""; // 機能名取得
cmb_val = combo_Func.getValue();
if (cmb_val != null) { // disable
switch (cmb_val) {
case "登録":
combo_Info.setVisible(false); //非表示
button.setVisible(true); //表示
```
```
}
// 4th method "When The Button is pushed..."
@FXML
void actionSetBukenName(){
if (!(combo_Func.getValue() == null)) {
String cmb_val = "";
cmb_val = combo_Func.getValue();
switch (cmb_val) {
case "登録":
addBukenInfo();
combo_Info.setValue("");
comboSet();
break;
case "修正":
if (combo_Info.getValue().equals("")) { //上記で宣言したものをget
```
combo_Info.setValue("");
comboSet();
break;
case "削除":
if (combo_Info.getValue().equals("")) {
```}
break;
}
} else {
Alert alrt = new Alert(AlertType.WARNING);
alrt.setHeaderText("エラー");
alrt.setContentText("実行する機能を選択してください。");
alrt.showAndWait();
}
}
// 5th method
@FXML
void bukenView() {
if (combo_Func.getValue() != "登録") { // != ~でなかったら
getBukenInfo();
}
}
// 6th method "Register"------------------------------------
public void addBukenInfo() {
```
}
// 8th method "Let me show data"-------------------------------------
public void getBukenInfo() {
```
}
// 9th method "Delete"---------------------------
public void deleteBukenInfo() {
```
}
}
}
Sorry that include Japanese. I am using postgreSQL.
Do I have to reimport some modular?
I'm creating room search system as training using Scene Builder stc. I am having so many trouble running my codes ...
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="paneRoot" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application2.Customer">
<children>
<Button fx:id="button" layoutX="110.0" layoutY="176.0" mnemonicParsing="false" onAction="#actionSetBukenName" text="実行" />
<ComboBox fx:id="combo_Func" layoutX="55.0" layoutY="50.0" onAction="#chngFunc" prefWidth="150.0" />
<ComboBox fx:id="combo_Info" layoutX="55.0" layoutY="109.0" onAction="#bukenView" prefWidth="150.0" />
<TextField fx:id="textField1" layoutX="382.0" layoutY="63.0" prefHeight="25.0" prefWidth="149.0" promptText="3文字以内" />
<TextField fx:id="textField2" layoutX="382.0" layoutY="122.0" prefHeight="25.0" prefWidth="149.0" promptText="10文字以内" />
<TextField fx:id="textField3" layoutX="382.0" layoutY="176.0" prefHeight="25.0" prefWidth="149.0" promptText="XXX-XXXX" />
<TextField fx:id="textField4" layoutX="382.0" layoutY="238.0" prefHeight="25.0" prefWidth="149.0" promptText="都道府県" />
<TextField fx:id="textField5" layoutX="382.0" layoutY="300.0" prefHeight="25.0" prefWidth="149.0" promptText="生駒市" />
<Label fx:id="label1" layoutX="264.0" layoutY="63.0" prefHeight="25.0" prefWidth="89.0" text="物件コード" />
<Label fx:id="label2" layoutX="264.0" layoutY="126.0" prefHeight="17.0" prefWidth="73.0" text="物件名" />
<Label fx:id="label3" layoutX="264.0" layoutY="180.0" prefHeight="17.0" prefWidth="73.0" text="郵便番号" />
<Label fx:id="label4" layoutX="264.0" layoutY="242.0" prefHeight="17.0" prefWidth="73.0" text="住所" />
<Label fx:id="label5" layoutX="264.0" layoutY="300.0" prefHeight="17.0" prefWidth="73.0" text="市区町村" />
</children>
</AnchorPane>
CodePudding user response:
Thank you all of you, I finally found my mistake. I changed the controller class name from "Customer" to "CustomerController". The former name of "Customer" is "testBuken".
( I made Buken (物件(bukken):real estate) version first and trying to recreate Customer version from buken classes.)
In FXML file, "fx:controller="application2.Customer"". This is incorrect.
This should be "fx:controller="application2.CustomerController"".
I really appreciate especially jewelsea and Slaw and kreopatra.
This was my very fisrt question. I'm so glad to ask help here.
CodePudding user response:
The runtime stack trace regarding the incorrect FXML location is a different issue (it is an additional error unrelated to the Eclipse highlighting, as far as I understand), see and follow the troubleshooting steps from:
Speculation on FXML highlighting in Eclipse
Your action functions can take an ActionEvent
as a parameter otherwise the signature does not match as standard onAction
method.
From the FXML intro guide an example handler definition:
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
}
I don’t use Eclipse but I guess that is what it is complaining about.
As noted by Slaw in comments, the FXML intro guide also states:
In general, a handler method should conform to the signature of a standard event handler; that is, it should take a single argument of a type that extends javafx.event.Event and should return void (similar to an event delegate in C#). The event argument often carries important and useful information about the nature of the event; however, it is optional and may be omitted if desired
So, you don't need to have the ActionEvent as a parameter, however, Slaw also states an opinion:
Most likely Eclipse is just not "smart" enough to realize that.
which I haven't verified that as I don't use Eclipse.
I do use Idea and verified that Idea is "smart" enough to realize that the ActionEvent parameter can be skipped in the controller method definition, so it does not highlight that omission as a potential error.