amadeus4dev / amadeus-java

Java library for the Amadeus Self-Service travel APIs
https://developers.amadeus.com/
MIT License
87 stars 69 forks source link

Null Object Reference #13

Closed MQ9Realper closed 6 years ago

MQ9Realper commented 6 years ago

Attempt to invoke virtual method 'java.lang.String com.google.gson.JsonElement.getAsString()' on a null object reference

The above error occurs when I call the Locations endpoint via this library. Below is the complete stacktrace:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.gson.JsonElement.getAsString()' on a null object reference at com.amadeus.Response.detectError(Response.java:69) at com.amadeus.HTTPClient.execute(HTTPClient.java:223) at com.amadeus.HTTPClient.unauthenticatedRequest(HTTPClient.java:117) at com.amadeus.HTTPClient.request(HTTPClient.java:202) at com.amadeus.HTTPClient.get(HTTPClient.java:66) at com.amadeus.referenceData.Locations.get(Locations.java:67)

Below, is how I am implementing the call:

**//Initialize using parameters new Thread(new Runnable() { @Override public void run() { Amadeus amadeus = Amadeus .builder(Constants.AMADEUS_CLIENT_ID, Constants.AMADEUS_SECRET_KEY) .build();

            try{
                Location[] locations = amadeus.referenceData.locations.get(Params
                        .with("keyword", "LON")
                        .and("subType", Locations.ANY));

                // The raw response, as a string
                locations[0].getResponse().getBody();
                Log.e("amadeus::", locations[0].getResponse().getBody());
            }catch (ResponseException ex){
                Log.e("amadeus::", ex.getResponse().toString());
            }
        }
    }).start();**
anthonyroux commented 6 years ago

I tried your code and it works on my side.

  1. Are you sure about your implementation of the Constants class and the API Key / API Secret you used?

  2. Are you sure about the dependencies you use: you need to import the SDK library version 1.1.0 and the gson library:

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.amadeus/amadeus-java -->
    <dependency>
        <groupId>com.amadeus</groupId>
        <artifactId>amadeus-java</artifactId>
        <version>1.1.0</version>
    </dependency>
</dependencies>
  1. Which version of JAVA and which flavour (Oracle, openjdk, other) do you use?