Reputation: 5386
I'm writing a java project and suddenly, out of nowhere eclipse is reporting that I have a problem with my code. It's specific to one file, but others are failing as well as they use a couple functions from the class in question, which they can't seem to find, the functions that is. I've tried almost everything I can think of to make this error go away.
To be specific the first error is:
Syntax error, insert "}" to complete ClassBody
Just to illustrate, here's the code:
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;
}
}
Is it just me or does anyone else get this error?
Any suggestions on how to fix it are welcome!
Upvotes: 0
Views: 1626
Reputation: 5386
Okay. I finally managed to fix the error.
As mentioned in the comments in the top post I could get it to compile if I cleared the constructor. Once I got it to compile I slowly copy pasted the code line by line into my project. I left out the ActionListeners and it compiled just fine. After this I slowly imported the ActionListener methods one by one and I found a line that resulted in the error. It was the line:
App.getSharedResources().changeRow(index, newRow); //line 106
This method was not yet implemented and it gave me that as an error after the above explained process. I could create the method and the rest of my code compiles as intended now. This was a really weird error.
Upvotes: 2
Reputation: 713
I have also faced similar issue sometime in past, could you please try to delete the error from 'Problems' view and perform a clean project afterwards, and see if it disappears.
If it does not help try: looking into the .log file created by eclipse in your workspace directory. That may hold a clue how to fix this.
Upvotes: 1