java - Eclipse 说我有编译错误,但我没有 - 如何修复?

标签 java eclipse compiler-errors

我正在编写一个 java 项目,突然 Eclipse 突然报告我的代码有问题。它特定于一个文件,但其他文件失败了,并且他们使用了相关类中的几个函数,但他们似乎找不到这些函数。我已经尝试了几乎所有我能想到的方法来消除这个错误。

  • 令人耳目一新的项目
  • 清洁项目
  • 删除项目并重新导入
  • 删除文件,创建新文件,粘贴内容
  • 删除了错误并清理了项目

具体来说,第一个错误是:

Syntax error, insert "}" to complete ClassBody

为了说明,这里是代码:

package view;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;

import model.HolderCompany;
import model.Row;
import viewmodel.App;

public class PanelMain extends JPanel {

    private PanelTable table;
    private DataDialog editDialog;
    private DataDialog addDialog;
    private ManageCompaniesDialog mcDialog;
    private PanelConsole consolePane;
    private JFrame frame;
    private ArrayList<Row> data;
    private ArrayList<HolderCompany> companies;

    private static String[] labelHeaders = {
        "ID",
        "Deployment Date",
        "IMEI",
        "Name",
        "Model",
        "Software Version",
        "A51 Device",
        "Holder Company",
        "Company E-mail",
        "Company Phone"
    }; //Here is the so called Syntax Error

    public PanelMain(){
        frame = new JFrame("Mobile Sensor Manager");

        setLayout(new BorderLayout());
        JPanel pane = new JPanel(new BorderLayout());

        consolePane = new PanelConsole();

        //Button Pane
        JButton addRow = new JButton("Add Row");
        addRow.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                addDialog = openDialog("Add Row");
                //Wait for return here
                Object[] data = addDialog.getData();
                if(data != null){
                    table.addRowToTable(data);
                    consolePane.write("Added row: " + table.dataToString(data), null);
                }
            }
        });

        JButton editRow = new JButton("Edit Row");
        editRow.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int index = table.getSelectedRow();
                if(index == -1){
                    //Write error message
                    consolePane.write("No row is selected!", null);
                } else {
                    Object[] d1 = table.getData(index);
                    editDialog = openDialog("Edit Row", data);
                    Row data =     App.getSharedResources().getData().get(index); 
                    editDialog = openDialog("Edit Row", data);
                    //Wait for return here
                    Object[] newData = editDialog.getData();
                    Row newRow = editDialog.getRow();
                    if(newData != null){
                        table.changeRowInTable(index, newData);
                        App.getSharedResources().changeRow(index, newRow);
                        consolePane.write("Changed row " + index + " to " + table.dataToString(newData), null);
                    }
                }
            }
        });

        JButton deleteRow = new JButton("Delete Row");
        deleteRow.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int index = table.getSelectedRow();
                if(index == -1){
                    //Write error message
                    consolePane.write("No row is selected!", null);
                } else {
                    consolePane.write("Removed row: " + table.tableIndexToString(index), null);
                    table.deleteRowFromTable(index);
                    App.getSharedResources().removeRow(index);
                }
            }
        });

        JButton manageCompanies = new JButton("Manage Companies");
        manageCompanies.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                mcDialog = openDialog();
            }
        });

        JButton clearDB = new JButton("Clear Database");
        JButton deleteDB = new JButton("Delete Database");

        JPanel buttonPane = new JPanel(new GridLayout(0, 1));
        TitledBorder buttonBorder = new TitledBorder("Buttons");
        buttonPane.setBorder(buttonBorder);

        buttonPane.add(addRow);
        buttonPane.add(editRow);
        buttonPane.add(deleteRow);
        buttonPane.add(new JSeparator());
        buttonPane.add(manageCompanies);
        buttonPane.add(new JSeparator());
        buttonPane.add(clearDB);
        buttonPane.add(deleteDB);

        //Table Pane
        table = new PanelTable();

        JPanel tablePane = new JPanel(new BorderLayout());
        TitledBorder dbContentBorder = new TitledBorder("Database Content");
        tablePane.setBorder(dbContentBorder);
        tablePane.add(table, BorderLayout.CENTER);

        pane.add(buttonPane, BorderLayout.LINE_END);
        pane.add(tablePane, BorderLayout.CENTER);
        pane.add(consolePane, BorderLayout.PAGE_END);

        add(pane, BorderLayout.CENTER);
    }

    public DataDialog openDialog(String name){
        Window win = SwingUtilities.getWindowAncestor(this);
        return new DataDialog(win, new DataTemplate(), name);
    }

    public DataDialog openDialog(String name, Object[] data){
        Window win = SwingUtilities.getWindowAncestor(this);
        return new DataDialog(win, new DataTemplate(), name, data);
    }

    public DataDialog openDialog(String name, Row data){
        Window win = SwingUtilities.getWindowAncestor(this);
        return new DataDialog(win, new DataTemplate(), name, data);
    }

    public ManageCompaniesDialog openDialog() {
        Window win = SwingUtilities.getWindowAncestor(this);
        return new ManageCompaniesDialog(win, new     ManageCompaniesTemplate(companies));
    }

    public void injectCompanies(ArrayList<HolderCompany> companies) {
        this.companies = companies;
    }

    public void injectData(ArrayList<Row> data) {
        this.data = data;
        table.injectDataToTable(data);
    }

    public void addMainToFrame(PanelMain main) {
        frame.add(main);
    }

    public void createAndShowGUI(){
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        //frame.setResizable(false);
        frame.pack();
        frame.setVisible(true);
    }

    public static String[] getHeaders() {
        return labelHeaders;
    }
}

编辑

只有我一个人遇到这个错误还是其他人遇到这个错误?

欢迎提供有关如何修复此问题的任何建议!

最佳答案

好的。我终于设法修复了这个错误。

正如顶帖评论中提到的,如果我清除了构造函数,我就可以编译它。一旦我完成编译,我就慢慢地将代码逐行复制粘贴到我的项目中。我省略了 ActionListeners,它编译得很好。之后我慢慢地一一导入ActionListener方法,我发现了导致错误的一行。这是一行:

App.getSharedResources().changeRow(index, newRow); //line 106

此方法尚未实现,在执行上述解释的过程后,它给了我一个错误。我可以创建该方法,并且代码的其余部分现在可以按预期进行编译。这是一个非常奇怪的错误。

关于java - Eclipse 说我有编译错误,但我没有 - 如何修复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38302913/

相关文章:

eclipse - Eclipse Luna PDT 中的 Smarty 突出显示

java - 使用 Eclipse 公开成员的 getter 和 setter

java - 重写有异常编译器错误的方法

java - 根据 ID 读取实际的 Firebase 记录

java - Gif 加载在 Firefox 中停止

java - 设计模式 : Reduce duplicate code from 2 methods that is almost the same in java

java - 获取 Jersey 反序列化为子类

java - guava-11.0.1.jar 和 eclipse 的 Maven 插件

compiler-errors - WinCE : What does mean the error: U1073: don't know how to make

c - 错误: 'for' loop declarations only in c99 mode