Caused by: java.lang.IllegalStateException: Please invoke the FileDownloader#init in Application#onCreate first.
at com.liulishuo.filedownloader.util.FileDownloadProperties.<init>(FileDownloadProperties.java:117)
at com.liulishuo.filedownloader.util.FileDownloadProperties.<init>(FileDownloadProperties.java:90)
at com.liulishuo.filedownloader.util.FileDownloadProperties$HolderClass.<clinit>(FileDownloadProperties.java:105)
at com.liulishuo.filedownloader.util.FileDownloadProperties.getImpl(FileDownloadProperties.java:109)
at com.liulishuo.filedownloader.services.FileDownloadService.onCreate(FileDownloadService.java:45)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2731)
at android.app.ActivityThread.access$1800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1361)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
是在自己定义的application类的onCreate()方法的第一行调用的init()方法 但是还是报错!
你看看是不是没有在 Manifest中定义Application,你可以看看源码 这个错误是因为连 ApplicationContext 都没有取到。这个是在FileDownloader#init 这的时候传入的。
清单文件application标签是的name写的是自己的application 是没有错的,所以目前我也找不到这个错误所在。。。
你可以clone demo下载看看,是没有问题的。
都有源码,你debug看下,看看在报错之前有没有调用过FileDownloader#init,init中 FileDownloadHelper.holdContext 这里持有了 ApplicationContext,你报错的地方就是发现 FileDownloadHelper 没有获取 ApplicationContext。
好的,我看看源码, 谢谢您的热心回答!
我也遇到这种情况,报没有初始化,最后定位到问题是 ,由于下载默认是有独立进程的,然后我在application里面做了进程名称的过滤,所以打LOG 虽然看是走到了init方法,但是其实是在主进程里面调用的,下载进程根本没有进入到初始化。
Most helpful comment
我也遇到这种情况,报没有初始化,最后定位到问题是 ,由于下载默认是有独立进程的,然后我在application里面做了进程名称的过滤,所以打LOG 虽然看是走到了init方法,但是其实是在主进程里面调用的,下载进程根本没有进入到初始化。