Android,LogCat 显示此错误:“不支持已弃用的线程方法”,这是什么?

发布于 2024-11-26 13:18:57 字数 1416 浏览 1 评论 0原文

运行程序后,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();
        }

enter image description here

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

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

发布评论

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

评论(2

梦里的微风 2024-12-03 13:18:57

您收到此异常是因为 Thread 的方法 stop()stop(Throwable) 已弃用,不应使用。

因为以这种方式停止线程是不安全的,并且可能会使您的应用程序和虚拟机处于不可预测的状态。

You receive this exception because Thread's methods stop() and stop(Throwable) are deprecated and should never be used.

Because stopping a thread in this manner is unsafe and can leave your application and the VM in an unpredictable state.

垂暮老矣 2024-12-03 13:18:57

屏幕截图表明您正在类 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 the Thread.stop() call with something else - the link has some pretty good example on how you should do instead of calling those methods.

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