如何从我的 jtable 中获取字符串值?

How do I get string values from my jtable?

我的 table 中填满了字符串,我正在尝试访问它们。我试过 '.getValueAt' 但它给了我一个错误。

代码是

'if (dayOfTheWeek=="Thursday"){
    int thursdayCOUNT=0;
    String[] THURSDAYSHOW=null;
    while (thursdayCOUNT<10){
         THURSDAYSHOW[thursdayCOUNT] = (String) timetable.getValueAt(thursdayCOUNT, 3);
         thursdayCOUNT=thursdayCOUNT+1;
          }'

错误是“线程异常 "AWT-EventQueue-0" java.lang.NullPointerException 在 my.UI.schedulerUI.jButton1ActionPerformed(schedulerUI.java:1401)'

现在您正在将 String[] 初始化为 null。你需要把它变成 new String["Some number goes here"]

看起来您正在使用 10 作为迭代长度,所以这可能是您制作数组的大小:

String[] THURSDAYSHOW= new String[10];

然后可以很容易地用 for 循环来替换 while 循环。这是一个完整的例子:

if (dayOfTheWeek.equals("Thursday")){
    String[] THURSDAYSHOW= new String[10];
    for(int i = 0; i < THURSDAYSHOW.length; i++)
    {
         THURSDAYSHOW[i] = (String) timetable.getValueAt(i, 3);
    }
}

最后一点,比较字符串时使用.equals()