-3

请帮我检查这段代码,在 AsyncTask 线程的 Void doInBackground(Void... voids) 中具有正确 API_KEY 和 API_SECRET 的 amadeus api 使我的应用程序崩溃。我已经尝试了一段时间,任何建议的解决方案都将不胜感激。

@Override 受保护的 Void doInBackground(Void... voids) {

        Amadeus amadeus = Amadeus.builder("API_KEY","API_SECRET").build();

        try{
            FlightDestination[] destination1 = amadeus.shopping.flightDestinations.get(Params.with("origin", "MAD"));
            if (destination1[0].getResponse().getStatusCode() == 200) {
                id = destination1[0].getType();
                name = destination1[0].getOrigin();
                email = destination1[0].getDestination();
                date1 = destination1[0].getDepartureDate();
                date2 = destination1[0].getReturnDate();
                FlightDestination.Price total= destination1[0].getPrice();
                double x = total.getTotal();
            }
            else { id = "Error";}
        }catch (ClientException e)
        {
            //id=e.getMessage();

        }catch (NetworkException e)
        {
            id = e.getMessage();

        }catch (NotFoundException e)
        {
            id = e.getMessage();
        }catch (ServerException e)
        {
           id =  e.getMessage();
        }catch (ParserException e)
        {
            id = e.getMessage();
        }catch (ResponseException e)
        {
            id = e.getMessage();
        }


        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);


        Intent data = new Intent(SportsTickets.this, Displayinfo.class);


        data.putExtra("type",id);
        data.putExtra("origin",name);
        data.putExtra("To",email);
        data.putExtra("departureDate", address);
        data.putExtra("total",gender);
        startActivity(data);



        pDialog.dismiss();

    }
4

1 回答 1

0

主机名、主机名和 SSL 已经由 SDK 的构建者设置,您可以这样做:

Amadeus amadeus = Amadeus.builder("API_KEY", "API_SECRET").build();


/* Find cheapest destinations from London */

FlightDestination[] flightDestinations = amadeus.shopping.flightDestinations.get(Params.with("origin", "LON"));

return flightDestinations;

不要忘记将您的 API_KEY 和 API_SECRET 替换为您在工作区中获得的那些,您可以按照本指南获取它们。

于 2018-11-20T08:17:19.307 回答