简体   繁体   English

Google App Engine:foursquare-java-api NullPointerException

[英]Google App Engine: foursquare-java-api NullPointerException

I have a backend server deployed to Google App Engine . 我有一个部署到Google App Engine的后端服务器。 When library venuesSearch() method is called ( https://github.com/clinejj/foursquare-api-java ), I receive a NullPointerException , but the response code from the Foursquare API seems to be ok (code:200). 当调用库venuesSearch()方法( https://github.com/clinejj/foursquare-api-java )时,我收到一个NullPointerException ,但是来自Foursquare API的响应代码似乎还可以(代码:200)。

The endpoints were generated automatically. 端点是自动生成的。 I don't understand if there's something wrong in the Foursquare API or if there's an error in my endpoint. 我不了解Foursquare API中是否存在错误或端点中是否存在错误。 Maybe the problem is the Callback_URL ? 也许问题出在Callback_URL

I tried to use either the same that I registered in the Foursquare developer app or skip it with null , but failure results in both cases. 我尝试使用在Foursquare开发人员应用程序中注册的相同名称,或者使用null跳过它,但是在两种情况下均会导致失败。 Someone who can help me please...thank you in advance. 可以帮助我的人...谢谢您。

This is my ApiMethod : 这是我的ApiMethod

private List<String> venuesName = null;

@ApiMethod(name = "searchVenues")
public StringObjectCollection searchVenues(@Named("ll")String ll) throws FoursquareApiException {


    String categoryIds = "4bf58dd8d48988d143941735,52e81612bcbc57f1066b79f4,4bf58dd8d48988d16c941735,"
            + "4bf58dd8d48988d16d941735,4bf58dd8d48988d16d941735,4bf58dd8d48988d1cb941735,4bf58dd8d48988d1ca941735,4bf58dd8d48988d1ca941735,"
            + "4bf58dd8d48988d1bd941735";
    String coordinates = ll;


    // First we need a initialize FoursquareApi. 
    FoursquareApi foursquareApi = new FoursquareApi(Constants.CLIENT_ID, Constants.CLIENT_SECRET, Constants.CALLBACK_URL);
    Result<VenuesSearchResult> result = foursquareApi.venuesSearch(coordinates, null, null, null, null, null, "browse",categoryIds, null, null, null,800 , null);

    StringObjectCollection venuesListObj = new StringObjectCollection();
    log.warning("codice:" + result.getMeta().getCode());

    if (result.getMeta().getCode() == 200) {

        // if query was ok we can finally we do something with the data

        for (CompactVenue venue : result.getResult().getVenues())
            venuesName.add(venue.getName());
    venuesListObj.setStringList(venuesName);
    return venuesListObj;
    } else {
        if (result.getMeta().getCode() == 404) throw new FoursquareApiException("nessun risultato");
        if (result.getMeta().getCode() == 500) throw new FoursquareApiException("errore del server");
        return venuesListObj;
    }
}

This instead is the code of Android client that perform the request: 这是执行请求的Android客户端的代码:

 private class SearchVenuesNearTask extends AsyncTask<Void, Void, StringObjectCollection> {

    @Override
    protected StringObjectCollection doInBackground(Void... params) {
        Foursquareendpoint.Builder builder = new Foursquareendpoint.Builder(
                AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
        builder = CloudEndpointUtils.updateBuilder(builder);
        Foursquareendpoint endpoint = builder.build();


        StringObjectCollection result = new StringObjectCollection();

        String ll = "45.478178,9.228031"; 

        try {
             result = endpoint.searchVenues(ll).execute();
        } catch (IOException e) {

            System.out.println(e.getMessage());
            result = null;
        }
        return result;
    }

    @Override
    protected void onPostExecute(StringObjectCollection result) {


    if (result == null || result.isEmpty() || result.size() < 1) {
        if (result == null) {
            resultVenues.setText("Retrieving venues failed.");


        } else {
            resultVenues.setText("No venues found.");

        }

      } else {

      Collection<String> res = result.getStringList();
      StringBuffer venuesFound = new StringBuffer();

      for (String venue : res){
        venuesFound.append(venue+ "\r\n");
      }

      resultVenues.setText(venuesFound.toString());


      }
    }

  }

This the error log: 这是错误日志:

 com.google.api.server.spi.SystemService invokeServiceMethod: cause={0}
 java.lang.NullPointerException
at it.polimi.dima.polisocial.foursquare.FoursquarePolisocialAPI.searchVenues(FoursquarePolisocialAPI.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:45)
at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160)
at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
at java.lang.Thread.run(Thread.java:724)

I made a mistake in the initialization here private List<String> venuesName = null; 我在这里的初始化中犯了一个错误: private List<String> venuesName = null; The correct version is : List<String> venuesName= new ArrayList<String>(); 正确的版本是: List<String> venuesName= new ArrayList<String>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM