简体   繁体   中英

Android App Crashing in some Devices Only, most of them Huawei

My App is working fine on almost all devices, but some customer giving reply as App not Opening Crashing like that. I never seen a real device crashing on the same App. Play store showing some crash reports and it include almost all type of device models but most of them were huawei devices..

java.lang.NullPointerException: 
  at www.ourshopee.com.fragment.TabDealOfDayFragment$2.onResponse (TabDealOfDayFragment.java:189)
  at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run (ExecutorCallAdapterFactory.java:65)
  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:6940)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

I am getting this Error in play console, but i working in all my testing device.

  implementation 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.0.0-RC1'
    implementation 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
    implementation 'com.squareup.retrofit2:retrofit:2.0.0-beta3'

Please Help me, your Help will be Appreciated..

TabDealFragment

 private void getProductsFromServer() {

        if (AppUtils.isConnectedToInternet(getContext(), true)) {
            llErrorLayout.setVisibility(View.INVISIBLE);

            Callback<DealOfDayResponse> callback = new Callback<DealOfDayResponse>() {
                @Override
                public void onResponse(Response<DealOfDayResponse> response) {


                    progress_deals.setVisibility(View.INVISIBLE);

                    if (response.body().getCode()==200) {


                        if (response.body().getData().getTempSection().size() != 0) {
                            dealOfDayList.addAll(response.body().getData().getTempSection());
                            dealproductListingAdapter.notifyDataSetChanged();
                        }

                        dealOfDayList.addAll(response.body().getData().getDealOfDay());
                        dealproductListingAdapter.notifyDataSetChanged();
                        llErrorLayout.setVisibility(View.INVISIBLE);
                        tvErrorText.setVisibility(View.INVISIBLE);
                        loading = true;
                    }
                }

                @Override
                public void onFailure(Throwable t) {
                 Log.d("Whats_My_Crash", String.valueOf(t));


                    progress_deals.setVisibility(View.INVISIBLE);
                    llErrorLayout.setVisibility(View.VISIBLE);
                    tvErrorText.setText(getString(R.string.err_unexpected));
                }
            };
            ApiManager.getApi().getService().getDealOfDayProducts(Constants.GET_DEALS_PRODUCTS, AppUtils.getCountryCode(getContext()), page, SUBCATEGORY_ID, BRAND_ID).enqueue(callback);
            loading = true;
        } else {
            llErrorLayout.setVisibility(View.VISIBLE);
            tvErrorText.setText(getString(R.string.err_internet));
        }
    }

Based on your description of the line there are two possibilities:

Either your backend returns a response that does not have any temp sections inside the body or that the complete body / data is empty and therefore returned as null by retrofit.

As body() can already return null you should improve your error handling and check if body is null, than if data returns null and finally if getTempSection() returns null.

The reasons for that are transparent for us. We do not know your backend and your data structure or API definition but you should always consider to deal with the absence of data without crashing.

SomeType body = response.body()
if (body.getCode() == 200) {
    SomeData data = body.getData()
    List<TempSection> tempSections = data.getTempSection()
    if (tempSections.size() > 0) {
        dealOfDayList.addAll(tempSections);
        dealproductListingAdapter.notifyDataSetChanged();
    }

    List<DealOfDay> dealsOfDay = data.getDealOfDay()
    if (dealsOfDay.size() > 0) {
        dealOfDayList.addAll(dealsOfDay);
        dealproductListingAdapter.notifyDataSetChanged();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM