I have a method for saving the values to ContentValues from remote server data as shown below:
public static ContentValues platformInfoToContentValues(@NonNull
GamePlatformInfoList platform) {
ContentValues values = new ContentValues();
values.put(TrackedPlatformEntry.COLUMN_PLATFORM_ID, platform.id());
values.put(TrackedPlatformEntry.COLUMN_PLATFORM_NAME, platform.name());
values.put(TrackedPlatformEntry.COLUMN_PLATFORM_ORIGINAL_PRICE, platform.original_price());
values.put(TrackedPlatformEntry.COLUMN_PLATFORM_RELEASE_DATE, platform.release_date());
values.put(TrackedPlatformEntry.COLUMN_PLATFORM_COMPANY_NAME, platform.company().name());
values.put(TrackedPlatformEntry.COLUMN_PLATFORM_SMALL_IMAGE, platform.image().small_url());
values.put(TrackedPlatformEntry.COLUMN_PLATFORM_MEDIUM_IMAGE, platform.image().medium_url());
values.put(TrackedPlatformEntry.COLUMN_PLATFORM_HD_IMAGE, platform.image().super_url());
return values;
}
In the last line the platform.company() value is null which is responsible for crashing my app.
My JSON
data is in the following format:
{ "company": null, "name": "PC", }
Here, the platform is GamePlatformInfoList data object which inturn "HAS-A" company as GameCompanyInfoShort data object inside it. Hence, I am using it as "platform.company().name()". How should I check for null before accessing "name()" property? Please help me.