1

This is the code I have, I am trying to have multiple images slide across the screen. The specific error shows up for "ThisClass" in the "TimerTask thisTimerTask = new ThisClass();" line. I appreciate any feed back available

package your.package2.namespace2;

import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.view.Display;
import android.widget.Button;
import android.widget.ImageView;
@SuppressWarnings("unused")

public class ChangeuppicksActivity extends Activity {

Display thisDisplay;
ImageView img, img4, img5, img7;
Timer timer;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    thisDisplay = getWindowManager().getDefaultDisplay();
    TimerTask thisTimerTask = new ThisClass();
    timer = new Timer();
    timer.scheduleAtFixedRate(thisTimerTask, 1000, 16);

    img = (ImageView) findViewById(R.id.pic1);
    img4 = (ImageView) findViewById(R.id.pic4);
    img5 = (ImageView) findViewById(R.id.pic5);
    img7 = (ImageView) findViewById(R.id.pic7);
}

public void doSomething() {
    int slideToPOS_X = (img.getLeft() - 7); 
    if (slideToPOS_X <= -img.getWidth()) {  
    int slideToPOS_X2 = (img4.getLeft() - 5);  
    if (slideToPOS_X2 <= -img4.getWidth()) {  
        slideToPOS_X2 = thisDisplay.getWidth();
    }

    img.layout(slideToPOS_X, 0, (slideToPOS_X + img.getWidth()), (0 + img.getHeight()));;

    img4.layout(slideToPOS_X2, 0, (slideToPOS_X2 + img4.getWidth()), (0 + img4.getHeight()));
}


class ThisClass extends TimerTask {
    @Override
    public void run() {
        ChangeuppicksActivity.this.runOnUiThread(new Runnable() {

            public void run() {
                doSomething();
            }
        });
    }
}
}
}
3
  • Could you provide some information about ThisClass? It is a subclass of TimerTask?
    – Jeremy D
    Feb 21, 2012 at 21:31
  • try making your ThisClass public .
    – Orkun
    Feb 21, 2012 at 21:36
  • As far as I know, subclasses have to be static, so try public static class ThisClass... But I'm not entirely sure whether this'll solve the problem.
    – m1ntf4n
    Feb 21, 2012 at 21:40

3 Answers 3

0

Not sure if this is the root cause of your problem, but looks like you have one too many close brackets at the bottom of your class. Try removing one of the '}' at the bottom of the class to see if that makes your compiler any happier.

You are also missing a close bracket in your doSomething() method. I may have broken your logic, but try replacing the bottom with this:

public void doSomething() {
int slideToPOS_X = (img.getLeft() - 7); 
if (slideToPOS_X <= -img.getWidth()) {  
    int slideToPOS_X2 = (img4.getLeft() - 5); 
}
if (slideToPOS_X2 <= -img4.getWidth()) {  
    slideToPOS_X2 = thisDisplay.getWidth();
}

img.layout(slideToPOS_X, 0, (slideToPOS_X + img.getWidth()), (0 + img.getHeight()));;

img4.layout(slideToPOS_X2, 0, (slideToPOS_X2 + img4.getWidth()), (0 + img4.getHeight()));
}


class ThisClass extends TimerTask {
@Override
    public void run() {
        ChangeuppicksActivity.this.runOnUiThread(new Runnable() {

            public void run() {
                doSomething();
            }
        });
    }
}
}
0

One of the close brackets at the end is superfluous and I think there should be an additional bracket closing the doSomething method. As it stands, ThisClass is defined inside the doSomething method - the second line of doSomething has an open bracket which isn't closed until the end of the class, which is hard to see as the code is not indented after the opening bracket.

0

Move ThisClass definition outside of the doSomething() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.