退出应用程序时出现错误

时间:2015-04-17 17:06:06

标签: android surfaceview

错误如下: “不幸的是,myAppname已经过时了。”

我在SurfaceView中制作游戏并使用许多位图和声音。 我的问题是;可能导致此错误的原因是什么?当我退出时,我有Atopd()并释放()声音。有一个线程正在运行,我不知道我是否必须杀死它,如果是这样,怎么样?当我退出时,位图仍然被加载,我是否必须释放它们,如果是,那怎么办?

我尝试在DDMS中发布错误图像,但似乎我没有足够的位置放置图像...这很有趣。

** ddms说;

E/AndroidRuntime(2009): FATAL EXCEPTION: Thread-3207
E/AndroidRuntime(2009): java.lang.NullPointerException
E/AndroidRuntime(2009):     at com.example.spaceinvaders.MainActivity$GameView.onDraw(MainActivity.java:478)
E/AndroidRuntime(2009):     at com.example.spaceinvaders.GameLogic.run(GameLogic.java:68)**

游戏逻辑中的第68行调用; this.mGameView.onDraw(帆布); 主要活动中的第478行是:canvas.drawColor(Color.rgb(38,132,3));

这是GameLogic类:

public class GameLogic extends Thread 
{
    private SurfaceHolder surfaceHolder;
    private GameView mGameView;
    private int game_state;
    public static final int PAUSE = 0;
    public static final int READY = 1;
    public static final int RUNNING = 2;

    public GameLogic(SurfaceHolder surfaceHolder, GameView mGameView) 
    {
        super();
        this.surfaceHolder = surfaceHolder;
        this.mGameView = mGameView;
    }

    public void setGameState(int gamestate) 
    {
        this.game_state = gamestate;
    }

    public int getGameState()
    {
        return game_state;
    }


    @SuppressLint("WrongCall")
    @Override
    public void run() 
    {
        Canvas canvas;

        while (game_state == RUNNING) 
        {
            canvas = null;


            try 
            {
                canvas = this.surfaceHolder.lockCanvas();
                long time_orig =System.currentTimeMillis();
                synchronized (surfaceHolder) 
                {
                    //this.mGameView.update();
                    //this.mGameView.onDraw(canvas);
                    try 
                    {
                        Thread.sleep(10);//(4);
                    }
                    catch (InterruptedException e1) 
                    {
                    }

                    long time_interim = System.currentTimeMillis();
                    int adj_mov = (int)(time_interim - time_orig);
                    mGameView.update(adj_mov);
                    time_orig = time_interim;
                    this.mGameView.onDraw(canvas);
                }
            }

            finally 
            {
                if (canvas != null) 
                {
                    surfaceHolder.unlockCanvasAndPost(canvas);
                }
            }
        }
    }
}

游戏正常,直到我按回按钮退出。

@ Nobu Games: 1.)在MainActivity中;

public void surfaceDestroyed(SurfaceHolder holder) 
{
    mGameLogic.setGameState(GameLogic.PAUSE);
}
在GameLogic中

2。)

            try 
            {
                Thread.sleep(10);//(4);
            }
            catch (InterruptedException e1) 
            {
            }

            long time_interim = System.currentTimeMillis();
            int adj_mov = (int)(time_interim - time_orig);
            mGameView.update(adj_mov);
            time_orig = time_interim;
            if(canvas != null)
                this.mGameView.onDraw(canvas);
        }
    }

    finally 
    {

.... 问题依然存在。我感谢你的时间和知识。

现在它的日志给了我这个错误:

04-17 15:08:42.592: E/AndroidRuntime(16286): FATAL EXCEPTION: main
04-17 15:08:42.592: E/AndroidRuntime(16286): android.app.SuperNotCalledException: Activity {com.example.spaceinvaders/com.example.spaceinvaders.MainActivity} did not call through to super.onDestroy()
04-17 15:08:42.592: E/AndroidRuntime(16286):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3300)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3329)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at android.app.ActivityThread.access$1200(ActivityThread.java:134)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1266)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at android.os.Looper.loop(Looper.java:137)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at android.app.ActivityThread.main(ActivityThread.java:4722)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at java.lang.reflect.Method.invokeNative(Native Method)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at java.lang.reflect.Method.invoke(Method.java:511)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
04-17 15:08:42.592: E/AndroidRuntime(16286):    at dalvik.system.NativeStart.main(Native Method)

这是我的第一篇文章,希望感谢大家为初学者提供的所有帮助。 LB

1 个答案:

答案 0 :(得分:0)

如果您@Override使用onDestroy()方法,则必须在super.onDestroy()中调用onDestroy()方法。

android.app.SuperNotCalledException: Activity {com.example.spaceinvaders/com.example.spaceinvaders.MainActivity} did not call through to super.onDestroy()