本文介绍了Android的改造简单的用法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重复使用一些来自教程来获得改造工作。这些都是重点班。
    主要活动
    包com.example.jc.retrofittest;

 进口android.os.Bundle;
进口android.support.v7.app.AppCompatActivity;
进口android.widget.TextView;进口com.example.jc.retrofittest.POJO.Model;进口retrofit.Callback;
进口retrofit.RestAdapter;
进口retrofit.RetrofitError;
进口retrofit.client.Response;公共类MainActivity扩展AppCompatActivity {    TextView的城市,地位,湿度,pressure;
    字符串URL =htt​​p://www.seecroatia.com/croatiamaps;
    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        城市=(的TextView)findViewById(R.id.txt_city);
        状态=(的TextView)findViewById(R.id.txt_status);
        湿度=(的TextView)findViewById(R.id.txt_humidity);
        pressure =(的TextView)findViewById(R.id.txt_ preSS);
        //使RestAdapter对象
        RestAdapter适配器=新RestAdapter.Builder()化setEndpoint(URL).build();
        city​​.setText(adapter.toString());
        //创建REST服务
        RestInterface restInterface = adapter.create(RestInterface.class);                //调用方法获取是否报告
                restInterface.getWheatherReport(新回拨<模型与GT;(){
                    @覆盖
                    公共无效成功(型号模型,响应响应){
                        city​​.setText(jur1e);
                        // status.setText(状态:+ model.getTyopInfo());                    }                    @覆盖
                    公共无效失败(RetrofitError错误){
                        city​​.setText(greska);
                        串merror = error.getMessage();
                    }
                });    }
}

Model.java

 公共类模式{    公共模型(){
    }    公共模型(INT idInfo,诠释所属类别){
        this.idInfo = idInfo;
        this.typeInfo =所属类别;
    }    公众诠释getIdInfo(){
        返回idInfo;
    }    公共无效setIdInfo(INT idInfo){
        this.idInfo = idInfo;
    }    公众诠释为getTypeInfo(){
        返回所属类别;
    }    公共无效setTypeInfo(INT所属类别){
        this.typeInfo =所属类别;
    }    私人诠释idInfo;
    私人诠释所属类别;}

RestInterface

 公共接口RestInterface {    @GET(/ getMarker.php)
    无效getWheatherReport(回拨<模型与GT; CB);}

酒店

 公共类酒店{
    私人字符串idHotel;
    私人字符串PBR;
    私人字符串mjesto;
    私人字符串naziv;
    私人字符串adresa;
    私人字符串网络;
    私人字符串电子邮件;
    私人字符串纬度;
    私人字符串经度;
    公众酒店(){
    }    公众酒店(字符串idHotel,PBR字符串,字符串mjesto,字符串naziv,字符串adresa,网页字符串,字符串电子邮件,字符串纬度,经度字符串){
        this.idHotel = idHotel;
        this.pbr = PBR;
        this.mjesto = mjesto;
        this.naziv = naziv;
        this.adresa = adresa;
        this.web =网络;
        this.email =电子邮件;
        this.latitude =纬度;
        this.longitude =经度;
    }    公共字符串getIdHotel(){
        返回idHotel;
    }    公共无效setIdHotel(字符串idHotel){
        this.idHotel = idHotel;
    }    公共字符串getPbr(){
        返回PBR;
    }    公共无效setPbr(字符串PBR){
        this.pbr = PBR;
    }    公共字符串getMjesto(){
        返回mjesto;
    }    公共无效setMjesto(字符串mjesto){
        this.mjesto = mjesto;
    }    公共字符串getNaziv(){
        返回naziv;
    }    公共无效setNaziv(字符串naziv){
        this.naziv = naziv;
    }    公共字符串getAdresa(){
        返回adresa;
    }    公共无效setAdresa(字符串adresa){
        this.adresa = adresa;
    }    公共字符串getWeb(){
        返回网页;
    }    公共无效setWeb(字符串网页){
        this.web =网络;
    }    公共字符串getEmail(){
        返回的电子邮件;
    }    公共无效setEmail(字符串email){
        this.email =电子邮件;
    }    公共字符串getLatitude(){
        返回纬度;
    }    公共无效setLatitude(字符串纬度){
        this.latitude =纬度;
    }    公共字符串getLongitude(){
        返回经度;
    }    公共无效setLongitude(字符串经度){
        this.longitude =经度;
    }
}

我的code八方通都会去Mainactivity故障部位。建议好吗?


解决方案

The endpoint is returning a JSONArray, not a JSONObject. your

Callback<Model> should be Callback<List<Model>>

You have to change also your Model class. idInfo and typeInfo are returned as String not as int

这篇关于Android的改造简单的用法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 12:38