0

I cannot figure out why my new activity wont start (I have omitted all the irrelevant code)

I am trying to display a main menu once the time has ended

public class GRenderer implements Renderer 
{

    public void timer ()
     {
        Game.currentGameTime = System.currentTimeMillis();
        Game.ellapsedTime = Game.currentGameTime - Game.gameStartTime;

        if (Game.ellapsedTime > 10000)
        {
            // THIS IS WHEN The GAME SHOULD END
            Toast.makeText(Game.context, "10Seconds", Toast.LENGTH_SHORT).show();
            Intent MainMenu = new Intent(getApplicationContext(),MainMenu.class); 
            startActivity(MainMenu);
        }
    }

    @Override
    public void onDrawFrame(GL10 gl) // when drawing to screen
    {
        timer();
    }
}

Here is the logcat:

12-13 18:28:28.500: E/AndroidRuntime(20184): FATAL EXCEPTION: GLThread 1386

12-13 18:28:28.500: E/AndroidRuntime(20184): Process: com.damienrenner.spacefruitshooter, PID: 20184

12-13 18:28:28.500: E/AndroidRuntime(20184): java.lang.NullPointerException

12-13 18:28:28.500: E/AndroidRuntime(20184):    at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)

12-13 18:28:28.500: E/AndroidRuntime(20184):    at com.damienrenner.spacefruitshooter.GameLoop.timer(GameLoop.java:280)

12-13 18:28:28.500: E/AndroidRuntime(20184):    at com.damienrenner.spacefruitshooter.GameLoop.onDrawFrame(GameLoop.java:296)

12-13 18:28:28.500: E/AndroidRuntime(20184):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)

12-13 18:28:28.500: E/AndroidRuntime(20184):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

2 Answers2

0

use following code:

    Intent MainMenu = new Intent(YourActivity.this,MainMenu.class); 
    startActivity(MainMenu);

instead of

    Intent MainMenu = new Intent(getApplicationContext(),MainMenu.class); 
    startActivity(MainMenu);

for more info about getApplicationContext() read this

Community
  • 1
  • 1
Shayan Pourvatan
  • 11,898
  • 4
  • 42
  • 63
0

you can only start an activity from another activity . Seems like GRenderer is not your activity.you should pass this to your GLSurfaceView activity.

nitesh goel
  • 6,338
  • 2
  • 29
  • 38