启动画面线程抛出错误。如何解决? (包括代码和错误)
我的启动画面有一些错误,我已经处理了一段时间但无法弄清楚。有没有比线程更好的方法来计时我的启动屏幕?我当前的线程出了什么问题?您能看出我的媒体播放器对象有问题吗?
我已经发布了我的飞溅课程的内容。希望我能在这些问题上得到一些指导。当我运行应用程序时这有效,但我只是不想出现错误。
-------------------------------------代码--------------------- ----------
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要在线程中调用
stop()
。这是一种已弃用的方法(它会导致虚拟机不稳定)并且不需要。 (当run()
方法返回时,线程将退出)。您可能打算为启动活动调用finish()
。这是有道理的。出于形式考虑,您可能希望在主线程而不是工作线程上调用
startActivity
和finish
。为此,请使用 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 therun()
method returns). You probably intended to callfinish()
for the splash activity. That would make sense.Just for form's sake, you might want to call
startActivity
andfinish
on the main thread instead of your worker thread. To do this, post a Runnable usingrunOnUIThread()
and call those two methods from the Runnable.