-3

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;
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
stuart
  • 11
  • 4

1 Answers1

2

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.

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
  • There not ment to be constants. Does public static final invoke that? – stuart Jan 26 '13 at 09:49
  • @stuart.. Using `final` keyword before a variable restricts taht variable value from being changed later on. If you are using `public static final`, the variable is either assigned a value in a static initializer block, or at the point of declaration, and are loaded once with the class. So, they are more or like constants only. – Rohit Jain Jan 26 '13 at 09:51
  • So if I wrote: public static String itemOfClothing = "Pants"; How could I change this later on Rob? – stuart Jan 26 '13 at 10:50
  • @stuart.. Since now, your variable is not `final`, you can change it to contain any string value. – Rohit Jain Jan 26 '13 at 10:51
  • I've just tried to change it like this but get the following error, any ideas? Sorry I'm very new to Java but really want to learn it. public static String itemOfClothing = "Pants"; public static String clothingEmotion = "I'm feeling left in the dark"; public static String user = "StuartWestgate"; <<<<<<<<<< Syntax error on token ";", , expected itemOfClothing = "Stuart"; – stuart Jan 26 '13 at 11:07
  • @stuart.. Are you changing the value still at the same place? You can do any assignment at the top level class. Read my answer again. You can only have declaration. To re-assign, you need to do that in some constructor, or some method.s – Rohit Jain Jan 26 '13 at 11:09
  • Ah I see. I'll look at doing it from a constructor. I'll write here if I able to get it to work Rob. Thanks Buddy. – stuart Jan 26 '13 at 11:11