0

I can't figure out ,why the data inside the onHandleWork becomes null , Here is my effort:

class OfferJobIntentService :JobIntentService {
            var oppoPayRepository:OppoPayRepository?=null
            var preferenceProvider: PreferenceProvider?=null

            constructor()  // secondary constructor

            constructor(oppoPayRepository:OppoPayRepository,preferenceProvider: PreferenceProvider):this(){  // secondary constructor
                this.oppoPayRepository = oppoPayRepository
                this.preferenceProvider=preferenceProvider
                Log.e("msg1--","oppoPayRepository1"+oppoPayRepository+"----"+preferenceProvider)

            }

            override fun onHandleWork(intent: Intent) {
                if(oppoPayRepository!=null){
                    Log.e("msg2--","oppoPayRepository2--"+oppoPayRepository)
                }else{
                    Log.e("msg3--","null")
                }

Logcat :

2019-10-27 00:50:06.629 20584-20584/com.oppopay.payments E/msg1--: oppoPayRepository1com.oppopay.payments.data.repository.OppoPayRepositoryImpl@b1e6ea3----com.oppopay.payments.data.provider.PreferenceProvider@6bcf5a0
2019-10-27 00:50:08.290 20584-20757/com.oppopay.payments E/LB: fail to open file: No such file or directory
2019-10-27 00:50:08.349 20584-20728/com.oppopay.payments E/msg3--: null
  • Why do you think it _won't_ be null? Your constructor isn't initializing any properties. – Ben P. Oct 26 '19 at 20:07
  • @BenP. but when the contructor is being called it's initializing the variable. As in logcat you can see msg1 is giving me the object – Barun Singh Oct 26 '19 at 20:27
  • Android will instantiate your JobIntentService using reflection and will invoke the no-arg constructor, which doesn't initialize the fields. It doesn't know where to find arguments for the two-arg constructor you've declared. – Egor Oct 26 '19 at 20:36
  • @Egor then how to resolve this issue,can you please help me out – Barun Singh Oct 26 '19 at 20:46
  • I also have this issue currently – CreativeJoe Apr 28 '20 at 12:54

0 Answers0