Results 1 to 6 of 6
  1. #1
    magicmojo is offline Member
    Join Date
    Feb 2011
    Location
    Netherlands
    Posts
    2
    Rep Power
    0

    Question Eclipse is making me go silly with it's syntax errors

    Eclipse is making me go silly with it's syntax errors


    I'm trying to get into Android-programming, and figured the program below (MagicButton) would be a nice intro, as well as a handy little tool for which I'd have some use. However, Eclipse keeps bugging me about having to complete the statement (with varying amounts of brackets (opening and closing!), semicolons etc.

    Java Code:
    package com.magicmojo.button;
    
        import java.util.Date;
    
        import android.app.Activity;
        import android.os.Bundle;
        import android.text.format.DateFormat;
    import android.view.Menu;
    import android.view.MenuInflater;
        import android.view.View;
        import android.view.View.OnClickListener;
    import android.widget.Button;
    
        public class MagicButton extends Activity {
           /** Called when the activity is first created. */
           @Override
           public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
           /*}*/
           
              Button button = (Button) findViewById(R.id.Button01);
              int ListSize = 5;
              final Date[] DateList = new Date[ListSize] ;
              
               final int DateCounter = 0; 
              
              button.setOnClickListener(new OnClickListener() {
                 public void onClick(View aView) {
                    // String dstring = DateFormat.getDateInstance().format(myDate);
                    //String dstring; // = new String(){
                    //dstring = DateFormat.getDateInstance().format(now);
                DateList[DateCounter] = new Date();
                DateCounter++;
                 };
              //}/*)*/{}
              //();{};};
        ;}
    
        /*@Override
        public boolean onCreateOptionsMenu(Menu menu) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.menu, menu);
            return true;
        }}*/
    it's all about this block: public class MagicButton extends Activity { } I've even gone so far as to insert a ; to appease Eclipse, but no luck! This is getting weirder and weirder.

    These are the errors Eclipse gives:

    Java Code:
    Description	Resource	Path	Location	Type
    Syntax error, insert ";" to complete Statement	MagicButton.java	/MagicButton/src/com/magicmojo/button	line 38	Java Problem
    Syntax error, insert ")" to complete Expression	MagicButton.java	/MagicButton/src/com/magicmojo/button	line 38	Java Problem
    Syntax error, insert "}" to complete ClassBody	MagicButton.java	/MagicButton/src/com/magicmojo/button	line 14	Java Problem
    Syntax error, insert "}" to complete MethodBody	MagicButton.java	/MagicButton/src/com/magicmojo/button	line 38	Java Problem

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    The syntax errors are not eclipse's fault, they're yours. Try compiling on the command line, and you'll get the same errors.

    Your indentation makes it hard to read, and I have no idea why you have so many commented out groups of curly brackets. Fix your indentation to make it easier to see what you're missing.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    magicmojo is offline Member
    Join Date
    Feb 2011
    Location
    Netherlands
    Posts
    2
    Rep Power
    0

    Question

    Quote Originally Posted by KevinWorkman View Post
    The syntax errors are not eclipse's fault, they're yours. Try compiling on the command line, and you'll get the same errors.

    Your indentation makes it hard to read, and I have no idea why you have so many commented out groups of curly brackets. Fix your indentation to make it easier to see what you're missing.
    Thanks for the reply, butthe messy brackets (which I've comemented out) were a result of Eclipse's suggestions. So, no, it's not entirely my fault (of course it is at least in part, I accept that), have I said that I don't have prior JAva-experience? Only C++ and some C#.

    I now have this (not how I've included the errors in the code):
    Java Code:
    package com.magicmojo.button;
    
        import java.util.Date;
    
        import android.app.Activity;
        import android.os.Bundle;
        import android.text.format.DateFormat;
    import android.view.Menu;
    import android.view.MenuInflater;
        import android.view.View;
        import android.view.View.OnClickListener;
    import android.widget.Button;
    
        public class MagicButton extends Activity {  //Syntax error, insert "}" to complete ClassBody
        											//Syntax error, insert "}" to complete ClassBody
    
        //} //Syntax error on token "}", delete this token
    
    
           /** Called when the activity is first created. */
           @Override
           public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
           }  //Syntax error on token "}", delete this token
    
           
           Button button = (Button) findViewById(R.id.Button01);
           int ListSize = 5;
           final Date[] DateList = new Date[ListSize] ;
              
            final int DateCounter = 0; 
              
            button.setOnClickListener(new OnClickListener() {
                public void onClick(View aView) {
                    // String dstring = DateFormat.getDateInstance().format(myDate);
                    //String dstring; // = new String(){
                    //dstring = DateFormat.getDateInstance().format(now);
                DateList[DateCounter] = new Date();
                DateCounter++;
                }; //Syntax error, insert ";" to complete Statement
                // Syntax error, insert "}" to complete MethodBody
                // Syntax error, insert "}" to complete ClassBody
                // Syntax error, insert ")" to complete Expression
            } //Syntax error, insert "}" to complete MethodBody
            /* I thought this bracket served to close class MagicButton!*/
    
        /*@Override
        public boolean onCreateOptionsMenu(Menu menu) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.menu, menu);
            return true;
        }}*/

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    This is getting more confusing by the way. These are indentation / incomplete code issues. And no one here can help you much with it.

    Better way, try to see if you have a closing bracket for every opening bracket and make sure that all the statements end with a semicolon.

    If anyone can fix this issue, it's you only. :)

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    You have so many basic errors in the brackets there that the compiler is simply confused as to what it is you are trying to do.

    So take a step back and redo the class, with proper indentation, and match up the brackets correctly. Do not continue to try and remove the errors one at a time based on the compiler suggestions.

    Do you know what a class should look like?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by magicmojo View Post
    Thanks for the reply, butthe messy brackets (which I've comemented out) were a result of Eclipse's suggestions. So, no, it's not entirely my fault (of course it is at least in part, I accept that), have I said that I don't have prior JAva-experience? Only C++ and some C#.
    Sorry, but this doesn't fly. Eclipse has powerful code formatting capabilities, but even it can't correctly format completely borked code. If you use only compilable code from the beginning (meaning fix any and all compile errors from the beginning and not adding any new code til the compile errors are fixed), this wouldn't happen. So reality check here: yes, it is all your fault. The sooner you understand this, the sooner you'll stop blaming Eclipse and start looking for a solution in your own code.

Similar Threads

  1. Syntax in eclipse
    By insectincest in forum Eclipse
    Replies: 1
    Last Post: 04-12-2010, 11:10 AM
  2. Eclipse Syntax Highlighting
    By garrettgjb in forum Eclipse
    Replies: 1
    Last Post: 08-24-2009, 03:10 PM
  3. Replies: 4
    Last Post: 06-25-2008, 08:09 PM
  4. Cannot get passed these syntax errors
    By MrKP in forum New To Java
    Replies: 1
    Last Post: 05-12-2008, 07:05 AM
  5. Making Plugins for Eclipse
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-17-2007, 08:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •