xuexiangjys / XUpdate

🚀A lightweight, high availability Android version update framework.(一个轻量级、高可用性的Android版本更新框架)
https://github.com/xuexiangjys/XUpdate/wiki
Apache License 2.0
2.32k stars 406 forks source link

使用仅下载功能出现Crash,报错NullPointerException: [UpdateManager.Builder] : updateHttpService == null #84

Closed cizkey closed 4 years ago

cizkey commented 4 years ago

问题描述(必填) 对问题进行清晰而简明的描述,把握问题的关键点。 目标:使用wiki只使用下载功能的代码,想要做后台下载,在通知栏显示下载进度。 使用:仅使用下载功能,直接Crash报错。

使用的XUpdate版本(必填) version 1.1.4

如何重现(必填) 重现的步骤: 使用wiki中仅使用下载功能,导致crash,报错信息为:

java.lang.NullPointerException: [UpdateManager.Builder] : updateHttpService == null

报错的框架的代码:

UpdateUtils.requireNonNull(this.updateHttpService, "[UpdateManager.Builder] : updateHttpService == null");

使用报错的代码 如果方便的话,贴一下程序截图和代码片段以帮助解释您的问题。 1、在Application中初始化

XUpdate.get().init(this);

2、使用仅下载功能

XUpdate.newBuild(activity)
       .apkCacheDir(AppContext.getApplication().getFilesDir().getAbsolutePath())
       .build()
       .download("http://static.ws.126.net/163/apk/newsapp/newsreader_netease_gw.apk", new OnFileDownloadListener() {
                                @Override
                                public void onStart() {
                                    Log.d(TAG, "onStart() called");
                                }

                                @Override
                                public void onProgress(float progress, long total) {
                                    Log.d(TAG, "onProgress() called with: progress = [" + progress + "], total = [" + total + "]");
                                }

                                @Override
                                public boolean onCompleted(File file) {
                                    Log.d(TAG, "onCompleted() called with: file = [" + file.getAbsolutePath() + "]");
                                    return false;
                                }

                                @Override
                                public void onError(Throwable throwable) {
                                    Log.d(TAG, "onError() called with: throwable = [" + throwable + "]");
                                }
                            });

3、报错信息

java.lang.NullPointerException: [UpdateManager.Builder] : updateHttpService == null

设备信息

附加信息 在此处添加任何有关该问题的任何其他说明。

cizkey commented 4 years ago

看错了,不好意思,初始化少了一个设置