请帮我检查一下这段代码,AsyncTask线程的Void doInBackground(Void ... voids)中包含正确的API_KEY和API_SECRET的amadeus api使我的应用崩溃了。我已经尝试了一段时间,任何建议的解决方案将不胜感激。
@Override protected 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();
}
答案 0 :(得分:0)
SDK的构建器已经设置了主机名,主机和SSL,您可以执行以下操作:
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,您可以按照此guide进行获取。