改造在Android中不起作用

时间:2016-11-25 12:09:06

标签: android retrofit

嗨,我是android的初学者。

在我的应用中,我使用Retrofit来集成Web服务,但我从服务器收到404错误!

我的代码如下,请帮帮我。

MainActivity: -

  String url = "MY URL";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //making object of RestAdapter
        RestAdapter adapter = new RestAdapter.Builder().setEndpoint(url).build();
        //Creating Rest Services
        RestInterface restInterface = adapter.create(RestInterface.class);

        restInterface.getWheatherReport(new Callback<List<Model>>() {
            @Override
            public void success(List<Model> models, Response response) {
                System.out.println("Response is====>" + response.toString());
            }

            @Override
            public void failure(RetrofitError error) {
                System.out.println("failure is====>" + error.toString());
            }
        });
    }

型号: -

private int paymenttypeid;
    private String cardType;

    public int getPaymenttypeid() {
        return paymenttypeid;
    }

    public void setPaymenttypeid(int paymenttypeid) {
        this.paymenttypeid = paymenttypeid;
    }

    public String getCardType() {
        return cardType;
    }

    public void setCardType(String cardType) {
        this.cardType = cardType;
    }

RestInterface: -

 @GET("/weather?q=London,uk")
    void getWheatherReport(Callback<List<Model>> cb);

服务器响应: -

[
  {
    "paymenttypeid": 1,
    "cardType": "Master Card"
  },
  {
    "paymenttypeid": 2,
    "cardType": "VISA"
  }
]

1 个答案:

答案 0 :(得分:0)

将字符串url =“URL”改为:“http://www.yourapi.com/something”,你会没事的