Why am I geting these bracket errors in my code?

1k Views Asked by At

I'm really not sure why it's doing this but it seems to be an issue with brackets. I'm getting the following errors while running this segment of code for Android in Eclipse:

private static final String TWITTER_ACCESS_TOKEN_URL = "http://api.twitter.com/oauth/access_token";
private static final String TWITTER_AUTHORZE_URL = "https://api.twitter.com/oauth/authorize";
private static final String TWITTER_REQUEST_URL = "https://api.twitter.com/oauth/request_token";

public static final String itemOfClothing;
public static final String clothingEmotion;
public static final String user;<<<<<<<<<<<<<<<<<<<<< Syntax error on token ";", { expected after this token


itemOfClothing = "pants";
clothingEmotion = "I'm feeling left in the dark";
user = "stuart";

public static String MESSAGE = itemOfClothing +": " + clothingEmotion + "! #" + user + "EmotionalClothing"; <<<<<<<<<<<<<<<<<<<<<< Syntax error, insert "}" to complete Block


public TwitterApp(Activity context, String consumerKey, String secretKey) {
    this.context = context;
1

There are 1 best solutions below

7
Rohit Jain On BEST ANSWER

You should initialize your strings at the point of declaration only, or inside a constructor. You can't have statements at the top-level class. You can just have declarations there.

So, one solution is, change the below statements: -

public static final String itemOfClothing;
public static final String clothingEmotion;
public static final String user;

/** You can't have below assignments directly under the top-level class **/
itemOfClothing = "pants";
clothingEmotion = "I'm feeling left in the dark";
user = "stuart";

to: -

public static final String itemOfClothing = "pants";
public static final String clothingEmotion = "I'm feeling left in the dark";
public static final String user = "stuart";

Or, another solution is, to move those assignments in a constructor, in which case, you would have to move the initialization of MESSAGE also in that constructor.

And also, if those variables are supposed to be constants, which I assume they are, as they are public static final, then your should use ALL_CAPS_WITH_UNDERSCORE to name them.