I`m doing my first steps on using Java and the eBay SDK (API).
In this code snippet I try to get a category list from eBay.
The call seems to work and I get a large result in the gcResponse object. Next step is to loop through the returned categories. The categories are returned in an array. The variable ct of type CategoryType holds one category. When debugging I can see the CategoryType object populated with data correctly(Name, Level, ...).
The ct.leafCategory has a value of 'false' indicating that this category isn't a leaf category.
But when I try to acces this field via the getLeafCategory() function I get a Null pointer exception (it is caught by the APIException-catch block).
Now I wonder how I can access this field correctly (all I want get back would be 'false'). I cannot access the field directly, because of course it seems to be private.
Does that mean, that the NPE happens inside the leafCategory()-function? But what could the function do except 'return leafCategory;'?
Thank's a lot for giving me a hint!
ApiContext apiContext = getContext(env, siteID);
GetCategoriesCall call = new GetCategoriesCall(apiContext);
GetCategoriesResponseType gcResponse = null;
call.setParentCategories(new String[] {"3187"});
call.setCategorySiteID(getSiteCode(siteID));
call.setDetailLevel(new DetailLevelCodeType[] {DetailLevelCodeType.RETURN_ALL});
try {
call.getCategories();
gcResponse = call.getResponse();
CategoryArrayType arr = gcResponse.getCategoryArray();
CategoryType ct = new CategoryType();
KMTgcResponse.categories = new KMTCategory[arr.getCategoryLength()];
for (int i=0; i<arr.getCategoryLength(); i++){
ct = arr.getCategory(i);
KMTgcResponse.categories[i] = new KMTCategory();
KMTgcResponse.categories[i].ID = ct.getCategoryID();
KMTgcResponse.categories[i].leafCategory = ct.isLeafCategory(); // NullPointerException here !!!
KMTgcResponse.categories[i].level = ct.getCategoryLevel();
KMTgcResponse.categories[i].name = ct.getCategoryName();
KMTgcResponse.categories[i].parentID = ct.getCategoryParentID();
}
response.getCategoriesResponse = KMTgcResponse;
response.rc = 1;
} catch (ApiException e) {
e.printStackTrace();
response.err_msg = Common.toString(e);
response.rc = -1;
} catch (Exception e) {
response.err_msg = Common.toString(e);
response.rc = -1;
}
}