启动画面线程抛出错误。如何解决? (包括代码和错误)

发布于 2024-12-04 02:22:05 字数 2469 浏览 0 评论 0原文

我的启动画面有一些错误,我已经处理了一段时间但无法弄清楚。有没有比线程更好的方法来计时我的启动屏幕?我当前的线程出了什么问题?您能看出我的媒体播放器对象有问题吗?

我已经发布了我的飞溅课程的内容。希望我能在这些问题上得到一些指导。当我运行应用程序时这有效,但我只是不想出现错误。

-------------------------------------代码--------------------- ----------

@Override
public void onCreate(Bundle savedInstanceState) {
 ......onCreate, hide window, and setting content view.......
        // Play Sound for startup
        mpSplash = MediaPlayer.create(this, R.raw.splashscream);
        mpSplash.start();
        final Splash splash = this;
        logoTimer = new Thread(){
        public void run(){
            try {
                synchronized(this){
                    // Wait given period of time or exit on touch
                    wait(4500);
                }
            } 
            catch(InterruptedException ex){ 
                ex.printStackTrace();
            }
            finish();
            mpSplash.stop();
            mpSplash.reset();
            //mpSplash.release();
            //mpSplash.release();
            // Run next activity
            Intent intent = new Intent();
            intent.setClass(splash, Game.class);
            startActivity(intent);
            stop();
        }
    };
    logoTimer.start();
}
// Splash screen touch events
@Override
public boolean onTouchEvent (MotionEvent evt)
{
    if(evt.getAction() == MotionEvent.ACTION_DOWN)
    {
        // Stop the introduction sounds
        mpSplash.stop();
        mpSplash.reset();
        //mpSplash.release();
        //mpSplash.release();
        synchronized(logoTimer){
            logoTimer.notifyAll();
        }
    }
    return true;
}

--------------------------------------------错误--- --------------------------------------

09-11 21:50:04.644: ERROR/MediaPlayer(460): stop called in state 1
09-11 21:50:04.644: ERROR/MediaPlayer(460): error (-38, 0)
09-11 21:50:04.654: ERROR/global(460): Deprecated Thread methods are not supported.
09-11 21:50:04.654: ERROR/global(460): java.lang.UnsupportedOperationException
09-11 21:50:04.654: ERROR/global(460):     at java.lang.VMThread.stop(VMThread.java:85)
09-11 21:50:04.654: ERROR/global(460):     at java.lang.Thread.stop(Thread.java:1379)
09-11 21:50:04.654: ERROR/global(460):     at java.lang.Thread.stop(Thread.java:1344)
09-11 21:50:04.654: ERROR/global(460):     at com.ss.lastzombie.Splash$1.run(Splash.java:61)

谢谢!!

I have some errors with my splash screen that I have been working on for a while and can't figure out. Is there a better way to time my splash screen than a thread? What's wrong with my current thread? Can you see an issue with my media player object?

I've posted the guts of my splash class. Hopefully I can get some direction on these issues. This works when I run the app but I just don't want to have errors.

-------------------------Code------------------------------

@Override
public void onCreate(Bundle savedInstanceState) {
 ......onCreate, hide window, and setting content view.......
        // Play Sound for startup
        mpSplash = MediaPlayer.create(this, R.raw.splashscream);
        mpSplash.start();
        final Splash splash = this;
        logoTimer = new Thread(){
        public void run(){
            try {
                synchronized(this){
                    // Wait given period of time or exit on touch
                    wait(4500);
                }
            } 
            catch(InterruptedException ex){ 
                ex.printStackTrace();
            }
            finish();
            mpSplash.stop();
            mpSplash.reset();
            //mpSplash.release();
            //mpSplash.release();
            // Run next activity
            Intent intent = new Intent();
            intent.setClass(splash, Game.class);
            startActivity(intent);
            stop();
        }
    };
    logoTimer.start();
}
// Splash screen touch events
@Override
public boolean onTouchEvent (MotionEvent evt)
{
    if(evt.getAction() == MotionEvent.ACTION_DOWN)
    {
        // Stop the introduction sounds
        mpSplash.stop();
        mpSplash.reset();
        //mpSplash.release();
        //mpSplash.release();
        synchronized(logoTimer){
            logoTimer.notifyAll();
        }
    }
    return true;
}

------------------------------Errors-----------------------------

09-11 21:50:04.644: ERROR/MediaPlayer(460): stop called in state 1
09-11 21:50:04.644: ERROR/MediaPlayer(460): error (-38, 0)
09-11 21:50:04.654: ERROR/global(460): Deprecated Thread methods are not supported.
09-11 21:50:04.654: ERROR/global(460): java.lang.UnsupportedOperationException
09-11 21:50:04.654: ERROR/global(460):     at java.lang.VMThread.stop(VMThread.java:85)
09-11 21:50:04.654: ERROR/global(460):     at java.lang.Thread.stop(Thread.java:1379)
09-11 21:50:04.654: ERROR/global(460):     at java.lang.Thread.stop(Thread.java:1344)
09-11 21:50:04.654: ERROR/global(460):     at com.ss.lastzombie.Splash$1.run(Splash.java:61)

Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萧瑟寒风 2024-12-11 02:22:05

不要在线程中调用 stop()。这是一种已弃用的方法(它会导致虚拟机不稳定)并且不需要。 (当run()方法返回时,线程将退出)。您可能打算为启动活动调用 finish()。这是有道理的。

出于形式考虑,您可能希望在主线程而不是工作线程上调用 startActivityfinish。为此,请使用 runOnUIThread() 发布 Runnable 并从 Runnable 调用这两个方法。

Don't call stop() in your thread. That's a deprecated method (it leads to instability in the VM) and is not needed. (The thread will exit when the run() method returns). You probably intended to call finish() for the splash activity. That would make sense.

Just for form's sake, you might want to call startActivity and finish on the main thread instead of your worker thread. To do this, post a Runnable using runOnUIThread() and call those two methods from the Runnable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文