gpt4 book ai didi

java - 在改造外部打印时值为空的数组列表

转载 作者:行者123 更新时间:2023-12-01 17:46:38 26 4
gpt4 key购买 nike

为什么我的数组列表的值为空?当它在改造之外打印时,即使我已经声明公共(public)变量 List<Profile> profileList = new ArrayList<Profile>();

我想在改造之外打印值数组列表,但没有成功。当在改造内打印值数组列表时,它起作用了。

这是我的代码

Hello.java

List<Profile> profileList = new ArrayList<Profile>();
apiService.getGetlistuser("getlistuser").enqueue(new Callback<ResponseDaftar>() {
@Override
public void onResponse(Call<ResponseDaftar> call, Response<ResponseDaftar> response) {
if (response.isSuccessful()) {
List<GetlistuserItem> getlistuserItemList = response.body().getGetlistuser();
for (int i = 0; i < getlistuserItemList.size(); i++) {
profileList.add(new Profile(
getlistuserItemList.get(i).getUserID(),
getlistuserItemList.get(i).getNickname()
));
}

/*
is working
for (Profile p : profileList){
Log.i("info", p.getUserid() + '\n' + p.getNickname());
}
*/


}
}

});

// my value is empty
for (Profile p : profileList){
Log.i("info", p.getUserid() + '\n' + p.getNickname());
}

改造界面

@POST("GetListNews.php")
@FormUrlEncoded
Call<ResponseDaftar> getGetlistuser(@Field("TableName") String paramTable);

最佳答案

您必须检查响应方法内的数据(您发表评论的位置),因为加载响应需要一些时间并且有时下一个语句在响应之前运行可用。

关于java - 在改造外部打印时值为空的数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54438736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com