Reputation: 33
I'm making an Android app, and I just started working on a piece of code that has to handle the movement of an ImageView in another class file. That's working fine (so far), so that's not what my question is about. This is the code I have:
public class BackgroundMovement extends MenuScreen {
public float heightDp = 0;
public float widthDp = 0;
public int isShowing = 0;
public void onCreate() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
heightDp = metrics.heightPixels / metrics.density;
widthDp = metrics.widthPixels / metrics.density;
}
public Random rand = new Random();
public int leftRight = rand.nextInt(2); [HERE]
if (isShowing == 0) {
}
}
You've probably noticed the very odd [HERE] in my code. I put that in because that's where Eclipse wants me to add in a {, and naturally, a } at the end. So my question is: why? I have no idea whatsoever, and I really want to fix it...
Upvotes: 0
Views: 76
Reputation: 59607
You have a bare control statement outside of any method or init block, at the top level of your class:
if (isShowing == 0) {}
This isn't valid java syntax, and Eclipse is complaining. But more significantly, the compiler will also complain about that line: as it is, your class won't compile.
Upvotes: 2