Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wikidata API always returns a Null Pointer Exception

I am using wikidata api to fetch a entity using its english title,

wdf = WikibaseDataFetcher.getWikidataDataFetcher();
eid = wdf.getEntityDocumentsByTitle("enwiki", entitle);

Earlier, with an older version of wikidata-api, I was able to run it smoothly. After updating to version 5.0.0, I always get the following error,

Exception in thread "main" java.lang.NullPointerException
    at org.wikidata.wdtk.wikibaseapi.ApiConnection.fillCookies(ApiConnection.java:544)
    at org.wikidata.wdtk.wikibaseapi.ApiConnection.sendRequest(ApiConnection.java:346)
    at org.wikidata.wdtk.wikibaseapi.WbGetEntitiesAction.wbGetEntities(WbGetEntitiesAction.java:187)

How to fix this?

like image 840
shyamupa Avatar asked Sep 27 '22 09:09

shyamupa


1 Answers

I get the same problem. I tried to use latest version from github and get the same exception. I execute the sample from documentation i.e the simple call:

Map<String, EntityDocument> results = wbdf.getEntityDocuments("Q80", "P31");

Seems code doesn't check for existence of a given cookie. I added the verification, recompiled and everything seems to work.

Go to ApiConnection.java:543

if (headerCookies != null)
    for (String cookie : headerCookies) {

No warranty ! :-)

like image 98
Christian Lautier Avatar answered Sep 30 '22 06:09

Christian Lautier