Results 1 to 6 of 6
- 02-21-2011, 01:37 PM #1
Member
- Join Date
- Feb 2011
- Location
- Netherlands
- Posts
- 2
- Rep Power
- 0
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.
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.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; }}*/
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
- 02-21-2011, 01:41 PM #2
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!
- 02-22-2011, 01:02 PM #3
Member
- Join Date
- Feb 2011
- Location
- Netherlands
- Posts
- 2
- Rep Power
- 0
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; }}*/
- 02-22-2011, 01:30 PM #4
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. :)
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 02-22-2011, 01:47 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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?
-
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
-
Syntax in eclipse
By insectincest in forum EclipseReplies: 1Last Post: 04-12-2010, 11:10 AM -
Eclipse Syntax Highlighting
By garrettgjb in forum EclipseReplies: 1Last Post: 08-24-2009, 03:10 PM -
Java Syntax for making 2 divs same height dynamically.
By jatrant in forum New To JavaReplies: 4Last Post: 06-25-2008, 08:09 PM -
Cannot get passed these syntax errors
By MrKP in forum New To JavaReplies: 1Last Post: 05-12-2008, 07:05 AM -
Making Plugins for Eclipse
By javaplus in forum New To JavaReplies: 0Last Post: 12-17-2007, 08:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks