NullPointerException at StackExchangeApi
-
In fact, I've got an app set up. stackapps and got Key. Then I found an example and tried to start it, but I'm finding a mistake, someone can tell you what the problem is, or show a suitable Tutorial to use it. StackExchangeApi
Here's the code:
public class Main { public static void main(String[] args) {
StackExchangeApiClientFactory factory = StackExchangeApiClientFactory.newInstance("dybйjLCjoйй0BA*g*rMYyDA(("); StackExchangeApiClient client = factory.createStackExchangeApiClient(); List<Question> questions = client.getQuestions(Question.SortOrder.HOT, new Paging(1, 20), new TimePeriod(new Date(), new Date()), EnumSet.of(FilterOption.INCLUDE_BODY, FilterOption.INCLUDE_COMMENTS)); for (Question q : questions) { System.out.println(q.getBody()); } }
}
and the tread of error:
Exception in thread "main" java.lang.NullPointerException
at com.google.code.stackexchange.client.impl.StackExchangeApiGateway.callApiMethod(StackExchangeApiGateway.java:269)
at com.google.code.stackexchange.client.impl.StackExchangeApiGateway.callApiMethod(StackExchangeApiGateway.java:233)
at com.google.code.stackexchange.client.impl.BaseStackExchangeApiClient.getQuestions(BaseStackExchangeApiClient.java:288)
at Main.main(Main.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
After a change of old liba to a new one,
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.google.code.stackexchange.client.query.impl.BaseStackOverflowApiQuery.<clinit>(BaseStackOverflowApiQuery.java:84)
at com.google.code.stackexchange.client.query.StackExchangeApiQueryFactory.newQuestionApiQuery(StackExchangeApiQueryFactory.java:179)
at Main.callStackExchange(Main.java:90)[INFO] StackExchange API Java SDK ......................... SUCCESS [ 1.747 s]
[INFO] stackexchange-java-schema .......................... SUCCESS [ 5.533 s]
[INFO] stackexchange-java-core ............................ FAILURE [01:30 min]
[INFO] stackoverflow-java-sdk-release ..................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:37 min
[INFO] Finished at: 2016-08-03T17:39:21+03:00
[INFO] Final Memory: 29M/347M
-
You probably use an outdated library. StackExchange changed API to version 2, try https://github.com/sanjivsingh/stackoverflow-java-sdk library.