Java 从数据库问题显示

Java 从数据库问题显示,java,eclipse,eclipse-indigo,Java,Eclipse,Eclipse Indigo,我正在用Eclipse Indigo和Java做作业。我必须为一所学校创建一个程序,该程序是一个拼写测试程序。我已经能够允许员工和学生登录,也可以更改他们的密码和编辑他们的帐户。我还能够创建测试并访问它们进行编辑。但我不能做的一件事是访问列表中的可用测试,以查看已设置了多少测试。我不知道在我的代码中修改什么来解决这个问题。为了显示测试,我创建了一个名为displayTest的方法。我已经使用哈希文件为测试创建了存储 在这里,我将测试的存储保存在一个哈希文件中 我继续在我的编码文档顶部添加了一个变

我正在用Eclipse Indigo和Java做作业。我必须为一所学校创建一个程序,该程序是一个拼写测试程序。我已经能够允许员工和学生登录,也可以更改他们的密码和编辑他们的帐户。我还能够创建测试并访问它们进行编辑。但我不能做的一件事是访问列表中的可用测试,以查看已设置了多少测试。我不知道在我的代码中修改什么来解决这个问题。为了显示测试,我创建了一个名为displayTest的方法。我已经使用哈希文件为测试创建了存储

在这里,我将测试的存储保存在一个哈希文件中

我继续在我的编码文档顶部添加了一个变量测试存储,使用:

public void addTest() {
   Test test = new Test();// create storage for a teacher
   test.input(); // read the teacher details in through the keyboard
   testFile.store(test); // store the teacher in the teacher file
我还能够编辑PC等来自我使用的另一个类的帐户,使用:

public void editTest() {
  String testNo;
  PC_Dialog editTests = new PC_Dialog("Edit Test", "Test No", "Find");// create a dialog box to ask for the teacher number
  editTests.choice();// display the dialog box
  testNo = editTests.getField(21); // get the teacherNo that has been entered
  test = (Test) testFile.retrieve(testNo); // retrieve the teacher from the file
  if (test != null) {// check if the teacher is found
     test.edit();// yes so display it for editing
     testFile.store(test); // store the teacher back in the teacher file
  } else
     JOptionPane.showMessageDialog(null, "Unable to find the test!");// not found so give an error message
}// end of method
但在显示测试中,我遇到了一些问题。displayTest允许教师查看所有的测试集,点击一个按钮,查看哪些测试需要编辑,哪些需要删除。但问题是if test.year==year{第一年下面有一条红线,当我在上面悬停时,它说“年份无法解决或不是一个字段”。有人能帮我尝试让displayTest部分从数据文件中收集测试并将它们显示在表上吗?我是Stackoverflow新手,一年多前只使用过一次。如果有人感到沮丧,我道歉我正在看一个新人的作品,但这实际上就像我第一次使用Stackoverflow。非常感谢您的帮助,谢谢

我已更改代码,因为:

public void displayTest() {
  Test testNo = new Test();
  Test yearGroup = new Test();
  Test date = new Test();
  PC_Table table = new PC_Table("Tests Available", 0, "Test Number, Date, Year Group", "OK");
  int row = 1;// a counter for the current row
  // prepare the file for serial access
  testFile.resetSerialAccess();
  // loop through all the records in the event file
  while (testFile.moreSerialRecords()) {
     // read the next record
     Test test = (Test) testFile.getNextSerialValue();{
        // retrieve the reason
        // add a row to the table and put the values in
        table.addRow();
        table.setValueAt(test.testNo, row, 1);
        table.setValueAt(test.date, row, 2);
        table.setValueAt(test.yearGroup, row, 3);
        row++;
  }
  table.choice();
  }

 }// end of method
表上没有显示测试数据库测试类中的任何内容。

您已经

Test date = new Test();
Test是类的名称。date是该类实例的名称。 你说错误在哪里

if (test.year == year)
我在代码中没有看到那一行,但你想要的是

if (date.year == year)
祝你好运

if (date.year == year)