Android,LogCat 显示此错误:“不支持已弃用的线程方法”,这是什么?
运行程序后,Logcat 显示一些错误(图)。 但程序运行后就没有问题了。我不明白问题出在哪里。
运行程序后,屏幕截图将显示 5 秒钟,然后将显示菜单(活动名称为 Scroll_View)。现在,LogCat 显示错误。 然而,当我点击每个按钮时,它工作正常,没有粗俗或其他任何东西。
这重要吗?
这是线程的代码:
protected boolean _active = true;
protected int _splashTime = 5000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
// thread for displaying the SplashScreen
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent("mobilesoft.asia.malaysia_directory.SplashScreen.Scroll_View"));
stop();
}
}
};
splashTread.start();
}
After running the program, Logcat shows some errors (picture).
But after that program runs and works without a problem. I can't understand where the problem is.
After running the program, Screen-shot will show for 5 seconds and after that menu (That the activity name is Scroll_View) will show. Now, LogCat shows error.
However, when I click on each button, it works fine without crass or anything else.
Is it important?
This is the code of thread:
protected boolean _active = true;
protected int _splashTime = 5000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
// thread for displaying the SplashScreen
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent("mobilesoft.asia.malaysia_directory.SplashScreen.Scroll_View"));
stop();
}
}
};
splashTread.start();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您收到此异常是因为 Thread 的方法
stop()
和stop(Throwable)
已弃用,不应使用。You receive this exception because Thread's methods
stop()
andstop(Throwable)
are deprecated and should never be used.屏幕截图表明您正在类 SplashScreen.java 中调用 Thread.stop()(第 35 行)。
Thread.stop()
已被弃用一段时间,因为它们过时、不安全并且可能对 JVM 产生负面影响 (http://download.oracle.com/javase/1.4.2/ docs/guide/misc/threadPrimitiveDeprecation.html),显然 Dalvik VM 不再支持这些线程方法。您应该能够用其他内容替换 Thread.stop() 调用 - 该链接有一些很好的示例,说明您应该如何做而不是调用这些方法。The screenshot indicates that you are calling Thread.stop() in the class SplashScreen.java (line 35).
Thread.stop()
has been deprecated for a while, because they are old, unsafe and can have negative effects on the JVM (http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html), and apparently the Dalvik VM doesn't support those thread methods any more. You should be able to replace theThread.stop()
call with something else - the link has some pretty good example on how you should do instead of calling those methods.