Handler is abstract;can not be instantiated android的解决

--begin by itlife365
Handler is abstract;can not be instantiated android
编写如下代码的时候
I am trying to use a Handler in my app. But when i instantiate it like this:

Handler handler = new Handler();


报错 I get the following error.

Gradle: error: Handler is abstract; cannot be instantiated

我点击自动提示Tip的解决方案时,自动提示了如下方法,
And when i check the solutions, it asks me to implement these methods:

Handler handler = new Handler() {
        @Override
        public void close() {

        }

        @Override
        public void flush() {

        }

        @Override
        public void publish(LogRecord record) {

        }
    };

因为之前没有使用过Hnadlers ,不知道这个是怎么回事。我只是想实现延时的效果而已,从示例代码执行的如下代码
I have never used Handlers before and i am using it just to call a method after some delay. To achieve that, I've used: 

handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //Do something after 100ms
            }
        }, 100);

baidu 后,找到原因了,导入错包了。I have imported a wrong Handler class
import java.util.logging.Handler;
Change it to,删除后改为如下代码解决了,没有在报错

import android.os.Handler;

why-Handler-can-not-be-instantiated-android
--end by itlife365

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

«    2024年11月    »
123
45678910
11121314151617
18192021222324
252627282930
搜索
标签列表
网站分类
最新留言
    文章归档
    友情链接

    Powered By Z-BlogPHP 1.7.3

    Copyright Your WebSite.Some Rights Reserved.闽ICP备11018667号-2