Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Absolute beginner with errors in code

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Absolute beginner with errors in code

    I could really use a hand here guys, i've been wrecking my brains trying to fix these errors, could someone please tell me what the errors are. Thank you for your time.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
     
    public class PetSurvey extends JFrame
    {
      public static voind main (string [] args)
      { 
        new PetSurvey () ;
      }
      JTextField name, phone, address;
        JRadioButton cat, dog , fish, oneOrMore , threeOrMore ;
        JCheckBox house, bungalow, appartment;
     
        Public PetSurvey ()
        {
          this.setTitle ("Pet Survey");
          this.setDefualtCloseOperation (JFrame.EXIT_ON_CLOSE);
            JPanel panel = new Jpanel ();
          panel1.SetLayout ( new GridBagLayout());
     
     
          ButtonListener bl = new ButtonListener ();
     
          AddItem( panel1, new JLabel ("Name"),
                   0, 0, 1, 1, GridBagConstraints.EAST);
            addItem(panel1, new JLabel ("Phone: "), 
                   0, 1, 1, 1, GridBagConstraints.EAST);
            addItem(panel1, new JLabel ("Phone: "), 
                    0, 1, 1, 1, GridBagConstraints.EAST);
              name = new JTextField (20);
             phone = new JTextField(10);
            address = new JTextField(20);
     
            addItem(panel1, name, 1, 0, 2, 1, GridBagConstraints.WEST);
             addItem(panel1, phone, 1, 1, 1, 1, GridBagConstraints.WEST);
              addItem(panel1, address, 1, 2, 2, 1, GridBagConstraints.WEST);
     
     
     
     Box sizeBox = Box.createVerticalBox();
     house = new JRadioButton("House");
     bungalow = new JRadioButton("bungalow");
     appartment = new JRadioButton("Appartment");
     ButtonGroup sizeGroup = new ButtonGroup();
     sizeGroup.add(house);
     sizeGroup.add(bungalow);
     sizeGroup.add(apprartment);
     
     
     
     sizeBox.add(house);
     sizeBox.add(bungalow);
     sizeBox.add(appartment);
     sizeBox.setBorder(BorderFactory.createTitledBorder("Select your house"));
     addItem(panel1, sizeBox, 0, 3, 1, 1, GridBagConstraints.NORTH);
     
     
     Box styleBox = Box.createVerticalBox ();
     thin = new JRadioButton("oneOrMore");
     thick = new JRadioButton("threeOrMore");
     ButtonGroup styleGroup = new ButtonGroup();
     
     styleGroup.add(oneOrMore);
     styleGroup.add(threeOrMore);
     styleBox.add(oneOrMore);
     styleBox.add(threeOrMore);
     styleBox.setBorder(BorderFactory.createTitledBorder ("How many pets do you have"));
     addItem(panel1, styleBox, 1, 3, 1, 1, GridBagConstraints.NORTH);
     
     Box topBox = Box.createVerticalBox();
     house = new JCheckBox("House");
     bungalow = new JCheckBox("Bungalow");
     appartment = new JCheckBox("Appartment");
     topBox.add(house);
     topBox.add(bungalow);
     topBox.add(appartment);
     topBox.setBorder(BorderFactory.createTitledBorder("Where do you live"));
     addItem(panel1, topBox, 2, 3, 1, 1,  GridBagConstraints.NORTH);
     Box buttonBox = Box.createHorizontalBox();
     okButton = new JButton("OK");
     okButton.addActionListener(bl);
     }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Absolute beginner with errors in code

    trying to fix these errors,
    Please copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Absolute beginner with errors in code

    It wont compile in the CMD or Dr Java or anything else
    I tried it in Ideone and got
    " compilation info
    Main.java:84: reached end of file while parsing
    }
    ^
    1 error "

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Absolute beginner with errors in code

    Check the pairing of {}s. Each { needs to have a pairing }.

    The statements in the last half of the code need to be properly indented to show the nesting level.
    Proper formatting will make finding mis-matched {}s much easier.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Absolute beginner with errors in code

    Hi, I've changed the code a little bit, could you compile it and tell me what you think? I'm not too sure what i'm doing if I'm honest..
    I understand if it's too much but thanks for the help. I've paired the {} together, well i think i did anyway. thanks again.

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
     
    public class PetSurvey extends JFrame
    {
      public static voind main (string [] args)
      { 
        new PetSurvey () ; 
      }
      JTextField name, phone, address;
        JRadioButton cat, dog , fish, oneOrMore , threeOrMore ;
        JCheckBox house, bungalow, appartment;
        }
        Public PetSurvey ()
        {
          this.setTitle ("Pet Survey");
          this.setDefualtCloseOperation (JFrame.EXIT_ON_CLOSE);
            JPanel panel = new Jpanel ();
          panel1.SetLayout ( new GridBagLayout());
     
          }
    {
          ButtonListener bl = new ButtonListener ();
     
          AddItem( panel1, new JLabel ("Name"),
                   0, 0, 1, 1, GridBagConstraints.EAST);
            addItem(panel1, new JLabel ("Phone: "), 
                   0, 1, 1, 1, GridBagConstraints.EAST);
            addItem(panel1, new JLabel ("Phone: "), 
                    0, 1, 1, 1, GridBagConstraints.EAST);
              name = new JTextField (20);
             phone = new JTextField(10);
            address = new JTextField(20);
     
            addItem(panel1, name, 1, 0, 2, 1, GridBagConstraints.WEST);
             addItem(panel1, phone, 1, 1, 1, 1, GridBagConstraints.WEST);
              addItem(panel1, address, 1, 2, 2, 1, GridBagConstraints.WEST);
                  }
    {
     
     
     Box sizeBox = Box.createVerticalBox();
     house = new JRadioButton("House");
     bungalow = new JRadioButton("bungalow");
     appartment = new JRadioButton("Appartment");
     ButtonGroup sizeGroup = new ButtonGroup();
     sizeGroup.add(house);
     sizeGroup.add(bungalow);
     sizeGroup.add(apprartment);
     
     }
    { 
     sizeBox.add(house);
     sizeBox.add(bungalow);
     sizeBox.add(appartment);
     sizeBox.setBorder(BorderFactory.createTitledBorder("Select your house"));
     addItem(panel1, sizeBox, 0, 3, 1, 1, GridBagConstraints.NORTH);
     
     }
    {
     Box styleBox = Box.createVerticalBox ();
     thin = new JRadioButton("oneOrMore");
     thick = new JRadioButton("threeOrMore");
     ButtonGroup styleGroup = new ButtonGroup();
    }
    {
     styleGroup.add(oneOrMore);
     styleGroup.add(threeOrMore);
     styleBox.add(oneOrMore);
     styleBox.add(threeOrMore);
     styleBox.setBorder(BorderFactory.createTitledBorder ("How many pets do you have"));
     addItem(panel1, styleBox, 1, 3, 1, 1, GridBagConstraints.NORTH);
     }
    {
     Box topBox = Box.createVerticalBox();
     house = new JCheckBox("House");
     bungalow = new JCheckBox("Bungalow");
     appartment = new JCheckBox("Appartment");
     topBox.add(house);
     topBox.add(bungalow);
     topBox.add(appartment);
     topBox.setBorder(BorderFactory.createTitledBorder("Where do you live"));
     addItem(panel1, topBox, 2, 3, 1, 1,  GridBagConstraints.NORTH);
     Box buttonBox = Box.createHorizontalBox();
     okButton = new JButton("OK");
     okButton.addActionListener(bl);
     
     
    				String msg = "You ordered a ";
    			if(small.isSelected()) msg += "xxx ";
    			if(medium.isSelected()) msg += "xxx";
    			if (large.isSelected ()) msg += "xxx ";
     
    			//String name = name.getText;
     
    			if(tops.equals(""))
     
    			msg += "you have selected no toppings";
    			else
     
    			msg += "the following toppings:\n "+ tops + base; 
     
     
    	JOptionPane.showMessageDialog(okButton, msg, "Your Results!", JOptionPane.INFORMATION_MESSAGE);
     
    	house.setSelected(false);
    	bungalow.setSelected(false);
    	appartment.setSelected(false);
    	cat.setSelected(false);
    	dog.setSelected(true);
    	fish.setSelected(true);
    			}
     
    			if (e.getSource() == closeButton)
    			{
    				System.exit(0);
    			}
    		}
    }
     
    }
     
    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Absolute beginner with errors in code

    The code still needs formatting. The }s should NOT be in the same column one below the other. Each should be indented and be in alignment beneath the start of the statement with the pairing {. That makes it easy to see matching pairs of {}s

    There still are too many statements that start in the first column. They need to be indented to show their nesting level.

    What errors are you getting now? Please copy the full text and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Absolute beginner with errors in code

    public static voind main
    I'm finding a lot of syntax errors. Surely this is not your actual code?

  8. #8
    Member
    Join Date
    Jan 2013
    Posts
    39
    My Mood
    Relaxed
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Absolute beginner with errors in code

    Wow this code has so many errors in it. Nearly 2/3 of the code has errors.
    I am just advising you to look at your code and take out any syntax errors like Strarstreak pointed out, also these keywords shouldnt have capitals. I advise you to get a IDE like Eclipse or netbeans.
    Also i have seen in your code that you are setting ALOT of viarables to the wrong type.
    Example : house = new JRadioButton("House"); but house isnt defined as a radioButton but as a checkbox.

    There are alot of these errors all over this code.

  9. #9
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Absolute beginner with errors in code

    Using an IDE like Eclipse will highlight errors so you can correct them as you type.

    Perhaps start with a simpler GUI in order to get used to the various components. Once that's running, expand it.

  10. #10
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: Absolute beginner with errors in code

    .
    Last edited by javaiscool; February 27th, 2013 at 02:11 AM. Reason: ...

Similar Threads

  1. Someone help me with my code it has some errors? Thanks!
    By skitheeast8 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 1st, 2012, 06:37 PM
  2. [SOLVED] Absolute Beginner Here, should be an easy question for anyone really.
    By Harrald in forum What's Wrong With My Code?
    Replies: 27
    Last Post: July 31st, 2012, 09:40 PM
  3. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  4. I still have errors. Can you PLEASE correct my code?!
    By sam30317 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 6th, 2011, 06:10 AM
  5. Please check the code for the errors
    By nrao in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 16th, 2010, 05:37 PM