我是学习ROS和改造的新手。任何人都可以帮我或指出其原因导致此错误的原因,基本上我想在硬件json下获取名称和状态。我不确定我的错误是否来自我的POJO模型。

最佳答案

E / mainAction:响应com.nera.rosbridgeclient.messages.robot_msgs.ObjectList@cea25bf
    硬件[Lcom.nera.rosbridgeclient.messages.robot_msgs.Object; @ 7ec748c


这不是Error/Exception,而是您的Log message

Log.e(" mainAction", " hardware"+ response.body().getHardware().toString());

上一行生成该error logs

原因:


  response.body()。getHardware()`


上一行将return设为arrayHardware。表示instance/objecthardware array

因此,当您将toString()用作instance/object


  response.body()。getHardware()。toString()


它将为您提供instance作为String

解:

您得到ArrayHardware作为响应。因此,您必须像下面这样迭代。

@Override
public void onResponse(Call<ObjectList> call, Response<ObjectList> response) {
       StringBuilder sb = new StringBuilder(); // add this line

       for(int i=0; i<response.body().getHardware().length; i++){
           Log.e(" mainAction", "  hardware"+ response.body().getHardware()[i].name);

           sb.append(response.body().getHardware()[i].name)); // here we append each hardware name to our string builder.
           sb.append(" "); // here we append a space separator after every hardware name, you can use whatever you want(like: newline[\n] or coma[,]).
       }
       textviewhardware.setText(sb.toString()); // now textview will show every hardware name.
}

关于java - 在Android retrofit 中获得回应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58945701/

10-11 22:14
查看更多