启动画面线程引发错误。如何解决? (code&放;纳入的错误) [英] Splash screen thread throwing errors. How to resolve? (Code & Errors Included)

查看:138
本文介绍了启动画面线程引发错误。如何解决? (code&放;纳入的错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些错误,我闪屏,我一直在努力了一段时间,想不通。有没有更好的方式来时候我的启动画面不是一个线程?这有什么错我的当前线程?你能看到我的媒体播放器对象的问题?

我已经张贴了我泼类的胆量。希望我能得到这些问题的一些方向。当我运行应用程序,但我只是不希望有错误,这工作。

------------------------- code --------------- ---------------

  @覆盖
公共无效的onCreate(捆绑savedInstanceState){
 ......的onCreate,隐藏窗口,并设置内容视图.......
        //播放声音的启动
        mpSplash = MediaPlayer.create(这一点,R.raw.splashscream);
        mpSplash.start();
        最后泼泼=这一点;
        logoTimer =新主题(){
        公共无效的run(){
            尝试{
                同步(本){
                    //等待触摸的时间或退出特定时期
                    等待(4500);
                }
            }
            赶上(InterruptedException的前){
                ex.printStackTrace();
            }
            完();
            mpSplash.stop();
            mpSplash.reset();
            //mpSplash.release();
            //mpSplash.release();
            //运行下一个活动
            意向意图=新的Intent();
            intent.setClass(飞溅,Game.class);
            startActivity(意向);
            停止();
        }
    };
    logoTimer.start();
}
//闪屏触摸事件
@覆盖
公共布尔onTouchEvent(MotionEvent EVT)
{
    如果(evt.getAction()== MotionEvent.ACTION_DOWN)
    {
        //停止引进声音
        mpSplash.stop();
        mpSplash.reset();
        //mpSplash.release();
        //mpSplash.release();
        同步(logoTimer){
            logoTimer.notifyAll();
        }
    }
    返回true;
}

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

  21 09-11:50:04.644:ERROR / MediaPlayer的(460):停止状态1叫
09-11 21:50:04.644:ERROR / MediaPlayer的(460):错误(-38,0)
09-11 21:50:04.654:ERROR /全局(460):德precated线程的方法不被支持。
09-11 21:50:04.654:ERROR /全局(460):java.lang.UnsupportedOperationException
09-11 21:50:04.654:ERROR /全局(460):在java.lang.VMThread.stop(VMThread.java:85)
09-11 21:50:04.654:ERROR /全局(460):在java.lang.Thread.stop(Thread.java:1379)
09-11 21:50:04.654:ERROR /全局(460):在java.lang.Thread.stop(Thread.java:1344)
09-11 21:50:04.654:ERROR /全局(460):在com.ss.lastzombie.Splash $ 1.run(Splash.java:61)

谢谢!


解决方案

不要叫停止()在你的线程

。这是一个去precated方法(它会导致不稳定的VM),也不需要。 (当运行()方法返回该线程将退出)。你可能打算叫完成()闪现活动。这将使感。

只是为了形式上的,你可能会想调用 startActivity 完成主线程,而不是你的工人在线。要做到这一点,使用后一个Runnable runOnUIThread(),并呼吁从Runnable的这两个方法。

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!!

解决方案

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.

这篇关于启动画面线程引发错误。如何解决? (code&放;纳入的错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆