gpt4 book ai didi

java - Jtable swing获取行数据

转载 作者:行者123 更新时间:2023-12-02 06:04:33 26 4
gpt4 key购买 nike

我在从 jTable 获取行数据时遇到一些问题:

for (int i = 0; i < TB_Accounts.getRowCount(); i++) {
username = TB_Accounts.getModel().getValueAt(i, i);
password = TB_Accounts.getModel().getValueAt(i, 1);

if (username == null || password == null) {
continue;
}

System.out.println("userName : " + username);
System.out.println("password : " + password);

if (!username.toString().equalsIgnoreCase("") && !password.toString().equalsIgnoreCase((""))) {
accouts.add(new Account(username.toString(), password.toString()));

System.out.println("in :: userName : " + username);
System.out.println("in :: password : " + password);
}
}

问题是 a 总是从表中获取除最后一行之外的所有数据,我不知道什么。

最佳答案

乍一看循环没有任何问题,但看起来第二行可能是罪魁祸首:

...
username = TB_Accounts.getModel().getValueAt(i, i);
...

当您继续处理行时,这可能会返回 null,并随后导致循环通过 continue 调用跳过,如果用户名或密码为 null,则会发生这种情况。更改为:

...
username = TB_Accounts.getModel().getValueAt(i,0);
...

关于java - Jtable swing获取行数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22406819/

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