-2

someone plz help me My app is getting Crash when im run the project

            if (!Constant_Api.aboutUsList.getInterstital_ad_click().equals("")) {
                Constant_Api.AD_COUNT_SHOW = Integer.parseInt(Constant_Api.aboutUsList.getInterstital_ad_click());
            }


 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.app.singlehotel.Item.AboutUsList.getInterstital_ad_click()' on a null object reference
    at com.app.singlehotel.Activity.MainActivity$2.onSuccess(MainActivity.java:266)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
sufyan
  • 1
  • 1

1 Answers1

1

My first guess would be that it is necessary to check if the Constant_Api.aboutUsList == null before calling getInterstital_ad_click() on it.

As the stacktrace points to invoking java.lang.String com.app.singlehotel.Item.AboutUsList.getInterstital_ad_click() so I don't believe it is making it to the .equals() check.

Update: It appears the offending line is within the if statement given within the original post. It is likely that the ConstantApi.AboutUsList is null. I am not entirely sure what it is because it is an import, but my best guess is that it is null because it is being defined within the scope of the for loop.

Test ConstantApi.AboutUsList == null before trying to invoke any methods on it, namely getInterstital_ad_click(). If it is null, you need to instantiate it within the correct scope.

Ps. thanks @a-local-nobody for the comments regarding my post as well as the question and supplied code.

Darkserum
  • 11
  • 4