You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio中使用MySQL、PHP、Volley获取积分降序玩家列表及RecyclerView展示时重复数据问题排查

问题排查与解决方案

嘿,我一眼就揪出问题所在了——你的player_object.java里的成员变量全都被声明成static了!

问题根源

static变量属于类本身,而非类的实例。这意味着你创建的所有player_object对象都会共享这四个变量的值。当你在循环里逐个创建玩家对象时,每一次赋值都会覆盖掉之前的数值,最后所有对象都会持有最后一个玩家的数据,RecyclerView自然就重复显示同一组信息了。

解决方案

把player_object里的static修饰符全部去掉,让它们成为每个实例独有的成员变量:

public class player_object { 
    private String gamer; 
    private int points; 
    private int photos; 
    private int highscore; 

    public player_object(String gamer, int points, int photos, int highscore) { 
        this.gamer = gamer; 
        this.points = points; 
        this.photos = photos; 
        this.highscore = highscore; 
    } 

    public String getPlayer(){ 
        return gamer; 
    } 

    public int getPoints(){ 
        return points; 
    } 

    public int getPhotos(){ 
        return photos; 
    } 

    public int getHighscore(){ 
        return highscore; 
    } 

    public void setPlayer(String gamer){ 
        this.gamer = gamer; 
    } 

    public void setPoints(int points){ 
        this.points = points; 
    } 

    public void setPhotos(int photos){ 
        this.photos = photos; 
    } 

    public void setHighscore(int highscore){ 
        this.highscore = highscore; 
    } 
}

额外验证提示

  1. 你的PHP代码已经正确返回了排序后的JSON数据(你也测试过功能正常),所以后端不需要做任何改动
  2. 修复Android端的模型类后,重启App再测试,RecyclerView应该就能正确展示每个玩家的独立数据,并且严格按照你设置的规则(积分降序→照片数升序→最高分降序)排列了

内容的提问来源于stack exchange,提问作者user15145293

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 08:42:37