繁体   English   中英

改造不适用于android

[英]Retrofit is not working in android

嗨,我是android的初学者。

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

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

主要活动:-

  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"
  }
]

将String url =“ URL”更改为类似的内容:“ http://www.yourapi.com/something ”,您会满意的

暂无
暂无

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

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