android-priority-jobqueue作业管理器null对象引用异常

时间:2016-03-28 07:50:30

标签: android android-priority-jobqueue

我在android studio 2.1预览版3中使用该库并对其进行编码, 当我开始运行应用程序时,抛出空指针异常并且错误指向jobManager = AppConfig.getInstance()。getJobManager();,"尝试调用虚方法' com.birbit.android。 jobqueue.JobManager pts.pmr.ptsdavao.AppConfig.getJobManager()'在null对象引用"

-class A

public class A extends Activity{

    JobManager jobManager;

    @Override
    protected void onCreate(){
    super.onCreate(savedInstanceState);
    //setup jobManager
    jobManager = AppConfig.getInstance().getJobManager();
    }

}

-class AppConfig
public class AppConfig extends Application {
    private static AppConfig instance;
    private JobManager jobManager;

    public AppConfig(){
        instance = this;
    }

    @Override
    public void onCreate(){
        super.onCreate();
        ConfigureJobManager();
    }

    private void ConfigureJobManager(){
        Configuration configuration = new Configuration.Builder(this)
                .customLogger(new CustomLogger() {
                    private static final String TAG = "PTS-JOBS";
                    @Override
                    public boolean isDebugEnabled() {
                        return true;
                    }

                    @Override
                    public void d(String text, Object... args) {
                        Log.d(TAG, String.format(text, args));
                    }

                    @Override
                    public void e(Throwable t, String text, Object... args) {
                        Log.e(TAG, String.format(text, args), t);
                    }

                    @Override
                    public void e(String text, Object... args) {
                        Log.e(TAG, String.format(text, args));
                    }
                })
                .minConsumerCount(1)//always keep at least one consumer alive
                .maxConsumerCount(3)//up to 3 consumers at a time
                .loadFactor(3)//3 jobs per consumer
                .consumerKeepAlive(120)//wait 2 minute
                .build();
        jobManager = new JobManager(configuration);
    }

    public JobManager getJobManager() {
        return jobManager;
    }

    public static AppConfig getInstance() {
        return instance;
    }

}

我似乎无法找到空指针异常的原因。由于AppConfig在JobManager上返回一个实例。

0 个答案:

没有答案