Java 安卓改型无响应

Java 安卓改型无响应,java,android,json,rest,retrofit,Java,Android,Json,Rest,Retrofit,嗨,我只是一个新的改装服务,并遵循本教程它工作得很好,并希望创建我自己的,所以我使用了一个新的json网站 包含 { "contacts": [ { "id": "c200", "name": "Ravi Tamada", "email": "ravi@gmail.com", "address": "xx-xx-xxxx,x - street, x - country",

嗨,我只是一个新的改装服务,并遵循本教程它工作得很好,并希望创建我自己的,所以我使用了一个新的json网站 包含

{
"contacts": [
    {
            "id": "c200",
            "name": "Ravi Tamada",
            "email": "ravi@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c201",
            "name": "Johnny Depp",
            "email": "johnny_depp@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c202",
            "name": "Leonardo Dicaprio",
            "email": "leonardo_dicaprio@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c203",
            "name": "John Wayne",
            "email": "john_wayne@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c204",
            "name": "Angelina Jolie",
            "email": "angelina_jolie@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "female",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c205",
            "name": "Dido",
            "email": "dido@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "female",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c206",
            "name": "Adele",
            "email": "adele@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "female",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c207",
            "name": "Hugh Jackman",
            "email": "hugh_jackman@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c208",
            "name": "Will Smith",
            "email": "will_smith@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c209",
            "name": "Clint Eastwood",
            "email": "clint_eastwood@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c2010",
            "name": "Barack Obama",
            "email": "barack_obama@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c2011",
            "name": "Kate Winslet",
            "email": "kate_winslet@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "female",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    },
    {
            "id": "c2012",
            "name": "Eminem",
            "email": "eminem@gmail.com",
            "address": "xx-xx-xxxx,x - street, x - country",
            "gender" : "male",
            "phone": {
                "mobile": "+91 0000000000",
                "home": "00 000000",
                "office": "00 000000"
            }
    }
]
我实现了自己的接口ContactAPI.java

public interface ContactsAPI {
@GET("/contacts/")
public void getContacts(Callback<List<Contact>> response);}
public interface ContactsAPI {
    @GET("/contacts/")
    public void getContacts(Callback<Contacts> response);
}
最后在MainActivity.class中实现了我的Restadapter

  public static final String ROOT_URL = "http://api.androidhive.info";
  private ListView listView;
  private List<Contact> contacts;
   RestAdapter adapter = new RestAdapter.Builder().setEndpoint(ROOT_URL).build();
    ContactsAPI api = adapter.create(ContactsAPI.class);

    api.getContacts(new Callback<List<Contact>>() {
        @Override
        public void success(List<Contact> list, Response response) {
            Toast.makeText(MainActivity.this,list.toString(),Toast.LENGTH_SHORT).show();
            showList();
        }

        @Override
        public void failure(RetrofitError error) {
            //you can handle the errors here
            Toast.makeText(MainActivity.this,"Error Occured:"+error.toString(),Toast.LENGTH_SHORT).show();
        }
    });
public静态最终字符串ROOT\u URL=”http://api.androidhive.info";
私有列表视图列表视图;
私人名单联系人;
RestAdapter adapter=new RestAdapter.Builder().setEndpoint(ROOT_URL.build();
ContactsAPI api=adapter.create(ContactsAPI.class);
api.getContacts(新回调函数(){
@凌驾
公共作废成功(列表、响应){
Toast.makeText(MainActivity.this,list.toString(),Toast.LENGTH_SHORT.show();
showList();
}
@凌驾
公共无效失败(错误){
//您可以在这里处理错误
Toast.makeText(MainActivity.this,“发生错误:+Error.toString(),Toast.LENGTH_SHORT).show();
}
});

该应用程序运行平稳,但延迟4秒后将提示一个错误,即公共无效失败(改型错误错误)。我不知道我遗漏了什么。我检查了我的代码,没有发现任何错误,请提前帮助我,谢谢。

如果json是这样,你需要一个包含以下内容的类:

public class Contacts {
    @SerializedName("contacts")
    @Expose
    private List<Contact> contacts = new ArrayList<Contact>();

    /**
     *
     * @return
     * The contacts
     */
    public List<Contact> getContacts() {
        return contacts;
    }

    /**
     *
     * @param contacts
     * The contacts
     */
    public void setContacts(List<Contact> contacts) {
        this.contacts = contacts;
    }

}
公共类联系人{
@序列化名称(“联系人”)
@暴露
private List contacts=new ArrayList();
/**
*
*@返回
*联系人
*/
公共列表getContacts(){
返回联系人;
}
/**
*
*@param联系人
*联系人
*/
公共联系人(列出联系人){
这个。联系人=联系人;
}
}
也在您的界面ContactAPI.java中

public interface ContactsAPI {
@GET("/contacts/")
public void getContacts(Callback<List<Contact>> response);}
public interface ContactsAPI {
    @GET("/contacts/")
    public void getContacts(Callback<Contacts> response);
}
公共接口联系人SAPI{
@获取(“/contacts/”)
公共联系人(回调响应);
}

同时检查此链接,因为“+”有问题,这是什么错误消息?知道错误肯定会有帮助。您在清单中有internet权限吗?@Juvi-这是日志E/Surface:getSlotFromBufferLocked:unknown buffer出现的错误:0xaa9ef1b0@Blackbelt-是的,我确实拥有清单上的internet权限,并且我的错误日志位于E/Surface:getSlotFromBufferLocked:unknown buffer:0xAA9EF1B0这是Android 6.0的一个版本。修正于6.0.1谢谢您的回复,先生,但青奥会给我的唯一结果是“Contact@824ec91"我错过了什么吗?好的,现在我明白了,你提供Contacts类的原因是为对象提供一个列表,然后我需要使用我的Contact类调用对象的参数thx给我的朋友和你我把我的开发时间减半谢谢!干杯