This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes I cant seem to fix this compile error !! please help me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I cant seem to fix this compile error !! please help me" Watch "I cant seem to fix this compile error !! please help me" New topic
Author

I cant seem to fix this compile error !! please help me

Howard owen
Greenhorn

Joined: Aug 21, 2007
Posts: 8
Hi people, Iv been working on code for a personal information storage system in Netbeans but i cant seem to get rid of this one error!! can anyone see anything wrong with it?

First off, I have greated the GUI so that all of the variables are the same as in the code.

I get this error:
Compiling 1 source file to C:\Doc\src\personalinformation\PersonalInfo.java:334: '}' expected
1 error
BUILD FAILED (total time: 0 seconds)

The error is at the very bottom, below the variable declaration. the illusive '}'



import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;

public class form extends JFrame {
public form() {
initComponents();
}

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PersonalInfo().setVisible(true);
}
});
}


private void okButtonMouseClicked(MouseEvent e) {

// Error checking - return 0, -1
// 0 if no problems, -1 if missing field or invalid data

// saving data to text file - return 0, -1
// 0 if saved properly, -1 if file corrupt/creation problem

String fileName = "data.txt";
String deliminator = ":";
String rec_marker = "#"; // place at start and end for calculating no. of records
String record = rec_marker + txt_name.getText() + deliminator +
txt_address.getText() + deliminator +
txt_city.getText() + deliminator +
txt_state.getText() + deliminator +
txt_zip.getText() + deliminator +
txt_phone.getText() + deliminator +
txt_birthday.getText() + rec_marker;

writeFile(fileName, record); //this over-writes existing data
}

private void clearButtonMouseClicked(MouseEvent e) {


txt_name.setText("");
txt_address.setText("");
txt_city.setText("");
txt_state.setText("");
txt_zip.setText("");
txt_phone.setText("");
txt_birthday.setText("");

}

private void writeFile(String strFileName, String strText){

boolean flStatus = false;
try {
//Checks if the file name is not null and not blank
if (strFileName != null && strFileName.length() > 0) {
java.io.BufferedWriter outStream = new java.io.BufferedWriter(
new java.io.FileWriter(strFileName));

// Writes text contents to the file
outStream.write(strText);
outStream.close();
flStatus = true;
}
}
catch (java.io.IOException e) {
System.out.println("Error: Invalid IO operation.");
}

}

public static void main(String args[]){
new form();
}

private void initComponents() {
// Component initialization
dialogPane = new JPanel();
contentPanel = new JPanel();
lbl_name = new JLabel();
txt_name = new JTextField();
lbl_address = new JLabel();
scrollPane1 = new JScrollPane();
txt_address = new JTextArea();
lbl_city = new JLabel();
txt_city = new JTextField();
lbl_state = new JLabel();
txt_state = new JTextField();
lbl_code = new JLabel();
txt_zip = new JTextField();
lbl_phone = new JLabel();
txt_phone = new JTextField();
lbl_birthday = new JLabel();
txt_birthday = new JTextField();
buttonBar = new JPanel();
okButton = new JButton();
clearButton = new JButton();
CellConstraints cc = new CellConstraints();


setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());

//dialog Pane
{
dialogPane.setBorder(Borders.DIALOG_BORDER);
dialogPane.setLayout(new BorderLayout());

//content Panel
{
contentPanel.setLayout(new FormLayout(
new ColumnSpec[] {
FormFactory.DEFAULT_COLSPEC,
FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW)
},
new RowSpec[] {
FormFactory.DEFAULT_ROWSPEC,
FormFactory.LINE_GAP_ROWSPEC,
new RowSpec(RowSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
FormFactory.LINE_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.LINE_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.LINE_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.LINE_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.LINE_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC
}));

// lbl_name
lbl_name.setText("Name:");
contentPanel.add(lbl_name, cc.xy(1, 1));
contentPanel.add(txt_name, cc.xy(3, 1));

// lbl_address
lbl_address.setText("Address:");
contentPanel.add(lbl_address, cc.xy(1, 3));

// scrollPane1
{
//txt_address
txt_address.setWrapStyleWord(true);
txt_address.setLineWrap(true);
scrollPane1.setViewportView(txt_address);
}
contentPanel.add(scrollPane1, cc.xy(3, 3));

// lbl_city
lbl_city.setText("City:");
contentPanel.add(lbl_city, cc.xy(1, 5));
contentPanel.add(txt_city, cc.xy(3, 5));

// lbl_state
lbl_state.setText("State:");
contentPanel.add(lbl_state, cc.xy(1, 7));
contentPanel.add(txt_state, cc.xy(3, 7));

// lbl_code
lbl_code.setText("Zip Code:");
contentPanel.add(lbl_code, cc.xy(1, 9));
contentPanel.add(txt_zip, cc.xy(3, 9));

// lbl_phone
lbl_phone.setText("Phone:");
contentPanel.add(lbl_phone, cc.xy(1, 11));
contentPanel.add(txt_phone, cc.xy(3, 11));

// lbl_birthday
lbl_birthday.setText("Birthday:");
contentPanel.add(lbl_birthday, cc.xy(1, 13));
contentPanel.add(txt_birthday, cc.xy(3, 13));
}
dialogPane.add(contentPanel, BorderLayout.CENTER);

// buttonBar
{
buttonBar.setBorder(Borders.BUTTON_BAR_GAP_BORDER);
buttonBar.setLayout(new FormLayout(
new ColumnSpec[] {
FormFactory.GLUE_COLSPEC,
FormFactory.BUTTON_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.BUTTON_COLSPEC
},
RowSpec.decodeSpecs("pref")));

// okButton
okButton.setText("OK");
okButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
okButtonMouseClicked(e);
}
});
buttonBar.add(okButton, cc.xy(2, 1));

//clearButton
clearButton.setText("Clear");
clearButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
clearButtonMouseClicked(e);
}
});
buttonBar.add(clearButton, cc.xy(4, 1));
}
dialogPane.add(buttonBar, BorderLayout.SOUTH);
}
contentPane.add(dialogPane, BorderLayout.CENTER);
pack();
setLocationRelativeTo(getOwner());
setVisible(true);
// End of component initialization
}


public class PersonalInfo extends javax.swing.JFrame {

/** Creates new form PersonalInfo */
public PersonalInfo() {
initComponents();
}


// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
lbl_name = new javax.swing.JLabel();
lbl_address = new javax.swing.JLabel();
lbl_city = new javax.swing.JLabel();
lbl_state = new javax.swing.JLabel();
lbl_code = new javax.swing.JLabel();
lbl_phone = new javax.swing.JLabel();
lbl_birthday = new javax.swing.JLabel();
txt_birthday = new javax.swing.JTextField();
txt_phone = new javax.swing.JTextField();
txt_zip = new javax.swing.JTextField();
txt_state = new javax.swing.JTextField();
txt_city = new javax.swing.JTextField();
txt_address = new javax.swing.JTextField();
txt_name = new javax.swing.JTextField();
okButton = new javax.swing.JButton();
clearButton = new javax.swing.JButton();

getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
lbl_name.setText("Name");
getContentPane().add(lbl_name, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 50, -1, -1));

lbl_address.setText("Address");
getContentPane().add(lbl_address, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 80, -1, -1));

lbl_city.setText("City");
getContentPane().add(lbl_city, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 140, -1, -1));

lbl_state.setText("State");
getContentPane().add(lbl_state, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 170, -1, -1));

lbl_code.setText("Postcode");
getContentPane().add(lbl_code, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 110, -1, -1));

lbl_phone.setText("Phone");
getContentPane().add(lbl_phone, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 230, -1, -1));

lbl_birthday.setText("Birthday");
getContentPane().add(lbl_birthday, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 200, -1, -1));

getContentPane().add(txt_birthday, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 200, 60, -1));

getContentPane().add(txt_phone, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 230, 60, -1));

getContentPane().add(txt_zip, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 110, 60, -1));

getContentPane().add(txt_state, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 170, 60, -1));

getContentPane().add(txt_city, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 140, 60, -1));

getContentPane().add(txt_address, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 80, 60, -1));

getContentPane().add(txt_name, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 50, 60, -1));

okButton.setText("Ok");
getContentPane().add(okButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 200, -1, -1));

clearButton.setText("Clear");
getContentPane().add(clearButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 230, -1, -1));

pack();
}// </editor-fold>

/**
* @param args the command line arguments
*/

// Variables declaration - do not modify
private javax.swing.JButton clearButton;
private javax.swing.JLabel lbl_address;
private javax.swing.JLabel lbl_birthday;
private javax.swing.JLabel lbl_city;
private javax.swing.JLabel lbl_code;
private javax.swing.JLabel lbl_name;
private javax.swing.JLabel lbl_phone;
private javax.swing.JLabel lbl_state;
private javax.swing.JButton okButton;
private javax.swing.JTextField txt_address;
private javax.swing.JTextField txt_birthday;
private javax.swing.JTextField txt_city;
private javax.swing.JTextField txt_name;
private javax.swing.JTextField txt_phone;
private javax.swing.JTextField txt_state;
private javax.swing.JTextField txt_zip;
// End of variables declaration

}
[ August 21, 2007: Message edited by: Howard owen ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Howard owen
Greenhorn

Joined: Aug 21, 2007
Posts: 8
Hi, just tried that, didnt work. it came up with thousands more errors :\ thanks anyway.


anyone else able to help?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if PersonalInfo class is supposed to be an inner class, move the additional }
to the end

// End of variables declaration

}
}//<-------------move to here
Howard owen
Greenhorn

Joined: Aug 21, 2007
Posts: 8
Hi, still not working
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

If you have a "real" Java editor available, tell it to format the code for you. Then the location of the missing brace should be obvious because the formatting will be wrong there.

Any Java IDE will do this (Eclipse, for example) or any simpler editor like JEdit, Emacs, etc. Notepad, Wordpad, etc, won't.


[Jess in Action][AskingGoodQuestions]
Howard owen
Greenhorn

Joined: Aug 21, 2007
Posts: 8
Yeah im using Netbeans which has an error checker, but it dosent say where the missing bracket is. It may be more than just a bracket but i dont know, thats why im appealing for help! if you could put it in whatever you use for java and try and find the mistake that would be great.

thanks
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Howard owen:
Hi, just tried that, didnt work. it came up with thousands more errors :\ thanks anyway...

Hmmm... My compiler only shows 100 errors. :roll: Eventually, I worked this down to 59, but since I don't have the jgoodies or netbeans packages, I can't take this too far.

Unfortunately, I think there really are numerous errors here -- not just a misplaced brace. For example, main is defined twice in the same class, there are incompatible types (e.g., trying to assign a JTextArea to a JTextField), trying to reference a non-static variable from a static context, a handful of variables that don't seem to be defined, and... Yes, a few mismatched braces.

I would start by properly indenting this code. Then just take the compiler errors one at a time.

I don't know how you got to this point, but a good practice is to work small: Write a few lines at a time, then compile. If you have errors, fix them at that point, before you have hundreds of lines of unmanageable code.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I cant seem to fix this compile error !! please help me
 
Similar Threads
Searching Collection
Null Pointer Exception - Driving Me Mad!
java unable to delete from array list
How to open a file using Java
Applet won't work in web page!