Hi!

I want to program a game where an image should move from the top to
the bottom.
Everytime, I start my game, I get the following error. In the
quellcode, I marked the line, where I get the error.
I have some questions:
1) How can I solve the problem?
2) What does "synchronized" in     private synchronized void doDraw
()     mean?

Greetings,
masr



Here is the error I get:

Leonard Frog [Android Application]
        DalvikVM[localhost:8613]
                Thread [<3> main] (Running)
                Thread [<15> Binder Thread #3] (Running)
                Thread [<13> Binder Thread #2] (Running)
                Thread [<11> Binder Thread #1] (Running)
                Thread [<17> Thread-9] (Suspended (exception ViewRoot
$CalledFromWrongThreadException))
                        LeonardFrog.doDraw() line: 78
                        LeonardFrog.access$2(LeonardFrog) line: 76
                        LeonardFrog$AnimationLoop.run() line: 151
                        Thread.run() line: 1058


Here is my game:



public class GoodGame extends Activity
{
     private ImageView image1;
     private int image1_y;

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

        image1 = (ImageView) findViewById(R.id.ImageView02);
        image1_y=0;

        (new Thread(new AnimationLoop())).start();
    }


    private synchronized void updatePhysics()
    {
        image1_y++;

    }

    private synchronized void doDraw()
    {

//#####################HERE I GET THE
ERROR###############################
        image1.layout(image1.getLeft(),image1_y,image1.getRight
(),image1.getBottom());
    }


    class AnimationLoop implements Runnable
    {
     public void run()
     {
          while(true)
          {
               while(running)
               {
                    try
                    {
                         Thread.sleep(100);
                    }
                    catch(InterruptedException ex) {}

                    updatePhysics();
                    doDraw();
               }
          }
     }
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to