【发布时间】:2021-02-28 16:15:12
【问题描述】:
当我运行我的程序时,出现如下编译错误:
com/mycompany/sistemcatatpoinkeaktifan/KemahasiswaanController.java:[65,20] cannot find symbol
symbol: method next()
location: variable rs of type javax.xml.transform.Result
com/mycompany/sistemcatatpoinkeaktifan/KemahasiswaanController.java:[66,51] cannot find symbol
symbol: method getInt(java.lang.String)
location: variable rs of type javax.xml.transform.Result
com/mycompany/sistemcatatpoinkeaktifan/KemahasiswaanController.java:[66,71] cannot find symbol
symbol: method getString(java.lang.String)
location: variable rs of type javax.xml.transform.Result
com/mycompany/sistemcatatpoinkeaktifan/KemahasiswaanController.java:[66,102] cannot find symbol
symbol: method getInt(java.lang.String)
location: variable rs of type javax.xml.transform.Result
4 errors
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.sistemcatatpoinkeaktifan;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javax.xml.transform.Result;
public class KemahasiswaanController implements Initializable {
@FXML
private TextField inputKegiatan;
@FXML
private Button buttonCreate;
@FXML
private Button buttonUpdate;
@FXML
private Button buttonDelete;
@FXML
private TableView<Menu> tvMenu;
@FXML
private TableColumn<Menu, Integer> colnomor;
@FXML
private TableColumn<Menu, String> coljenisKegiatan;
@FXML
private TableColumn<Menu, Integer> colpoin;
public Connection getConnection(){
try{
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:E:\\Documents\\Sem 5\\RPL\\punya maria\\SistemCatatPoinKeaktifanMaria\\db\\database.db");
return conn;
} catch (Exception e){
System.out.println(e.getMessage());
return null;
}
}
public ObservableList<Menu> getMenuList(){
ObservableList<Menu> menuList = FXCollection.observableArrayList();
Connection conn = getConnection();
String query = "SELECT JenisKegiatan, Poin FROM KemahasiswaanNatasha";
Statement st;
Result rs;
ObservableList<Menu> MenuList = null;
try{
st = conn.createStatement();
rs = (Result) st.executeQuery(query);
Menu KegiatanKemahasiswaan;
while(rs.next()){
KegiatanKemahasiswaan = new Menu(rs.getInt("nomor"), rs.getString("jenisKegiatan"), rs.getInt("poin"));
MenuList.add(KegiatanKemahasiswaan);
}
}catch(SQLException ex){
ex.printStackTrace();
}
return MenuList;
}
public void ShowMenu(){
ObservableList<Menu> list = getMenuList();
colnomor.setCellValueFactory(new PropertyValueFactory<Menu, Integer>("nomor"));
coljenisKegiatan.setCellValueFactory(new PropertyValueFactory<Menu, String>("Kegiatan"));
colpoin.setCellValueFactory(new PropertyValueFactory<Menu, Integer>("Poin"));
tvMenu.setItems(list);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
ShowMenu();
}
private static class FXCollection {
private static ObservableList<Menu> observableArrayList() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public FXCollection() {
}
}
}
【问题讨论】:
-
找不到符号 symbol: method next() location: variable rs of type javax.xml.transform.Result => 这意味着 Result 类没有 next() 方法,但你尝试在某个地方调用它。很可能,您的意思是 ResultSet 或类似的东西
-
确实,您错误地将 executeQuery 的结果转换为
Result,这应该是java.sql.ResultSet -
a) 基本上与 javafx 无关 - 调试涉及尽可能多地隔离问题 b) java 命名约定 c) 请将堆栈跟踪格式化为代码 - 按原样不可读:)
-
嘿..你为什么要恢复格式?有人为你做了你的工作,你又把它毁了? *难以置信