-3

I'm developing a game via Andengine for Android platforms. I created a LevelEditorScene and I wanna use Toast messages on it like:

 Toast.makeText(activity, " Upload Started ...", Toast.LENGTH_SHORT).show();

But it creates an error. Here is the logCat: http://s9.postimg.org/jfqwsvx7j/Captu1re.png

What is the problem, can u solve it?


Here are my whole codes:

LevelEditorScene.java

@Override
public void createScene()
{

    //ekrana eleman eklemek için
    setOnSceneTouchListener(this);



     Rectangle save = new Rectangle(100, 400, 80, 50, vbom){
           @Override
            public boolean onAreaTouched(TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {

               if(pTouchEvent.getAction() == MotionEvent.ACTION_DOWN)
               {
                   Toast.makeText(activity, " Upload Started ...", Toast.LENGTH_SHORT).show();





                 /*  getAllObjectsData();
                   createXmlFile(x, y, distanceordirection, type);
                   */

               }
               return true;
           }
        };
     save.setColor(1.0f,0.4f,0.5f);
     registerTouchArea(save);
     attachChild(save);
  }

SceneManager.java

 public void loadEditorScene(final Engine mEngine)
{
    setScene(loadingScene);
    ResourcesManager.getInstance().unloadMenuTextures();
    mEngine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() 
    {
        public void onTimePassed(final TimerHandler pTimerHandler) 
        {
            mEngine.unregisterUpdateHandler(pTimerHandler);
            ResourcesManager.getInstance().loadGameResources();
            editorScene = new LevelEditorScene();
            setScene(editorScene);
        }
    }));
}

GameActivity.java

     public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws IOException
{
    mEngine.registerUpdateHandler(new TimerHandler(2f, new ITimerCallback() 
    {
            public void onTimePassed(final TimerHandler pTimerHandler) 
            {
                mEngine.unregisterUpdateHandler(pTimerHandler);
                SceneManager.getInstance().createMenuScene();
            }
    }));
    pOnPopulateSceneCallback.onPopulateSceneFinished();
}
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
user1391058
  • 265
  • 4
  • 19

1 Answers1

0

if you use Toast in static function it must not work

you can do this add this before oncreate function:

static Activity thisActivity = null;

and in oncreate function:

thisActivity = this;

and then you can use Toast:

Toast.makeText(thisActivity , "message", Toast.LENGTH_SHORT).show();