请在ScheduledExecuterService问题上使用Null Object引用解决未知问题,

时间:2019-06-05 15:11:44

标签: java android

我收到以下错误。

Attempt to invoke interface method 'java.util.concurrentScheduledFuture java.util.concurrent.ScheduledExecutorService.scheduledWithfixdedDelay(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit)' on a null object reference.  

我看不到这里为空。我已阅读

What is a NullPointerException, and how do I fix it?

,我在这里看不到null。手动填写所有值,并由Runnable设置task1。我在这里想念什么或做错什么了?

//这是相关的进口(我认为);

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;

//在这里,我设置了backgroundExecutor

ScheduledExecutorService backgroundExecutor;  

//这是可运行进程延迟的开始。

    public void start() {
    Runnable task1=new Runnable() {
        public void run() {
            pauseFunction();
        }
    };

    backgroundExecutor.scheduleWithFixedDelay(task1, 5, 0, TimeUnit.SECONDS);
}

我期望TimePassed函数被调用为true。

但是我遇到上述Null错误。

0 个答案:

没有答案