How do I get string values from my jtable?

I have my table filled in with strings and I'm trying to access them. I've tried '.getValueAt' but it gives me an error.

code is

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

error is 'Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at my.UI.schedulerUI.jButton1ActionPerformed(schedulerUI.java:1401)'

Answers


Right now you are initializing your String[] to null. You need to make it a new String["Some number goes here"]

It looks like you are using 10 as your length of iteration, so that could be how big you make the array:

String[] THURSDAYSHOW= new String[10];

This then can be easily followed up with a for loop to replace your while loop. Here is a full example:

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

One last note, use .equals() when comparing Strings.


Need Your Help

the KeyListener on won't work: Java

java keylistener

I wrote some code to create a little square on the screen, but when I press the left button, nothing seems to happen. The rectangle doesn't move, and "Move Left." doesn't get printed out in the con...

How can I disable work php files in a specific directory in My site

php .htaccess directory

I have folder containing several files and sub-folders such as the following: