0

It's very weird, my code works fine on android below 8, it works fine on some phones with android 8 but on some samsung with android 8, it returns null /

This is my code :

getHomePage = ApiConnection.client.create(GetHomePage::class.java)
    getHomePage.getHomePage(Func.getUid(this))
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({ result ->

            val Gallery = result.gallery;
            val Category = result.category
            val Product = result.products

            if (Gallery != null)
                GalleryMaker(this@MainActivity, Gallery)

            if(Category!=null){
                val catAdapter = CategoryAdapter(this@MainActivity, Category);
                rcCats?.adapter = catAdapter
                catAdapter.setOnItemClickListener(object : CategoryAdapter.ClickListener {
                    override fun onClick(pos: Int, aView: View) {
                        val item = Category.get(pos)
                        val intent: Intent = Intent(this@MainActivity, Products::class.java)
                        intent.putExtra("title", item.name)
                        intent.putExtra("id", item.id)
                        startActivity(intent)
                    }
                })
            }

            if(Product!=null){
                val productsAdapter = ProductAdapter(this@MainActivity, Product);
                rcProducts?.adapter = productsAdapter
            }


            customProgressDialog?.dismiss("")
        }, { error ->
            Log.v("this", error.printStackTrace().toString())
        })

the result for category , product and category are null . one again , the same app works fine on android pre 8 , it does work fine with android 8 in another phone but with samsung android version 8 , it doesn't work and return null

This is my api connection :

    object ApiConnection {
    val BaseUrl = Const.BaseUrl
    val client: Retrofit
        get() {
            val gson = GsonBuilder()
                .setLenient()
                .create()

            ///for Logging
            val interceptor = HttpLoggingInterceptor()
            interceptor.level = HttpLoggingInterceptor.Level.BODY
            val client = OkHttpClient.Builder().addInterceptor(interceptor).build()


            var retrofit = Retrofit.Builder()
                .baseUrl(BaseUrl)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .client(client)
                .build()
            return retrofit
        }
}

this is a log cat before I place !=null for listeners

Fatal Exception: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method b.a.a.a.b, parameter list
   at ir.s.cardiomeds.Adapters.CategoryAdapter.(Unknown Source:7)
   at ir.s.cardiomeds.MainActivity$getData$1.accept(Unknown Source:29)
   at ir.s.cardiomeds.MainActivity$getData$1.accept(Unknown Source:2)
   at io.reactivex.internal.observers.ConsumerSingleObserver.onError(Unknown Source:7)
   at io.reactivex.internal.operators.single.SingleObserveOn$ObserveOnSingleObserver.run(Unknown Source:14)
   at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(Unknown Source:2)
   at android.os.Handler.handleCallback(Handler.java:789)
   at android.os.Handler.dispatchMessage(Handler.java:98)
   at android.os.Looper.loop(Looper.java:164)
   at android.app.ActivityThread.main(ActivityThread.java:6944)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58

0 Answers0