gpt4 book ai didi

java - 从jtable中获取对象

转载 作者:行者123 更新时间:2023-12-02 06:53:00 24 4
gpt4 key购买 nike

我试图从 JTable 中获取一个对象并将其传输到另一个 jform,您可以在其中编辑值。但是当我想在 jform 中显示对象的变量时,我得到一个空指针异常。

private void taBuyersMouseClicked(java.awt.event.MouseEvent evt) {                                      
// TODO add your handling code here:
if (evt.getClickCount() == 2) {
Model.TabelModel model = (Model.TabelModel) taBuyers.
getModel();
int row = taBuyers.getSelectedRow();
if (row != -1) {
int Id = (int) model.getValueAt(row, 0);
String Name = (String) model.getValueAt(row, 1);
String LastName = (String) model.getValueAt(row, 2);
Date gebDate = (java.sql.Date) model.getValueAt(row, 3);
Boolean seller = Boolean.valueOf(model.getValueAt(row, 4).toString());
String comment = (String) model.getValueAt(row, 5);
Person pers = new Person(Id,Name,LastName, gebDate,seller,comment);
MakePerson person = new MakePerson();
person.setPerson(pers);
person.setVisible(true);
}
}

}

这是我调试时显示的人员,我看到该对象并且所有变量都已填充。

    public void setPerson(Person pers) {
teId.setText(String.valueOf((pers.getId()))); => here I get the nullpointerexception
}


private javax.swing.JTextField teId;

这是错误:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gui.scherm.Personscreen.MakePerson.setPerson(MakePerson.java:42)
at gui.scherm.Personscreen.taBuyersMouseClicked(Personscreeb.java:176)
at gui.scherm.Personscreen.access$000(Personscreen.java:30)
at gui.scherm.Personscreen$1.mouseClicked(Personscreen.java:110)

最佳答案

改变这个

private javax.swing.JTextField teId ; 

import javax.swing.JTextField;


private JTextField teId = new JTextField();

关于java - 从jtable中获取对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17793845/

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