Java 为什么改装会从webservice返回空值?

Java 为什么改装会从webservice返回空值?,java,android,retrofit,Java,Android,Retrofit,我有一个ASP.NET web API服务,它返回{“id”:1,“family”:“mohsen”}。为什么改型会从中返回null API接口: public interface ApiRefrence { @GET("hello") Call<List<product>> GetProduct(); } 产品类别POJO: public class product { @SerializedName("id") @Expose

我有一个ASP.NET web API服务,它返回
{“id”:1,“family”:“mohsen”}
。为什么改型会从中返回null

API接口:

public interface ApiRefrence {
    @GET("hello")
    Call<List<product>> GetProduct();
}
产品类别POJO:

public class product {
    @SerializedName("id")
    @Expose
    int id;
    @SerializedName("family")
    @Expose
    String family;

    public int getId() {
        return id;
    }

    public String getFamily() {
        return family;
    }
}
主要活动:

public class MainActivity extends AppCompatActivity {
    EditText txt1,txt2;
    List<product> lst;
    TextView txt3;
    private ApiRefrence ref;

    Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txt3 = (TextView)findViewById(R.id.textView) ;
        txt1 = (EditText)findViewById(R.id.editText);

        txt2 = (EditText)findViewById(R.id.editText2);

        ref = ApiClinet.GetApiClinet().create(ApiRefrence.class);

        Call<List<product>> call = ref.GetProduct();

        call.enqueue(new Callback<List<product>>() {
            @Override
            public void onResponse(Call<List<product>> call, Response<List<product>>
    response) {               
                lst = response.body();
                txt3.setText(response.body().get(0).family.toString());
            }

            @Override
            public void onFailure(Call<List<product>> call, Throwable t) {

            }
        });
    }
}
public类MainActivity扩展了AppCompatActivity{
编辑文本txt1,txt2;
列表lst;
TextView-txt3;
私人参考文献;
按钮btn;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt3=(TextView)findViewById(R.id.TextView);
txt1=(EditText)findViewById(R.id.EditText);
txt2=(EditText)findViewById(R.id.editText2);
ref=ApiClinet.GetApiClinet().create(apreference.class);
Call Call=ref.GetProduct();
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应
答复{
lst=response.body();
setText(response.body().get(0.family.toString());
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
}
});
}
}

将基本url更改为:
public静态最终字符串BasesUrl=”http://185.105.239.32/api/test/";

将您的API界面更改为:

public interface ApiRefrence {
   @GET("hello")
   Call<product> GetProduct();  
}
公共接口引用{
@得到(“你好”)
调用GetProduct();
}
更改您的响应代码:

Call<product> call = ref.GetProduct();

call.enqueue(new Callback<product>() {
  @Override
  public void onResponse(Call<product> call, Response<product>
response) {               
   lst=response.body();

   txt3.setText(response.body().getFamily());
  }

  @Override
   public void onFailure(Call<product> call, Throwable t) {

   }
 });
Call Call=ref.GetProduct();
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应
答复{
lst=response.body();
setText(response.body().getFamily());
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
}
});

未解决错误java.lang.RuntimeException:无法启动活动组件信息{com.example.amin.myapplication/com.example.amin.myapplication.MainActivity}:java.lang.IllegalArgumentException:baseUrl必须以/:
Call<product> call = ref.GetProduct();

call.enqueue(new Callback<product>() {
  @Override
  public void onResponse(Call<product> call, Response<product>
response) {               
   lst=response.body();

   txt3.setText(response.body().getFamily());
  }

  @Override
   public void onFailure(Call<product> call, Throwable t) {

   }
 });