I keep getting the nullPointerException for this. It's a word search program. I'm aware that its one of the ugliest programs you will ever see, but I just need it to work. Every class name is underlined in yellow and the entire 2d Object array is underlined in yellow. Heres the error message in console:
Exception in thread "main" java.lang.NullPointerException
at ProjGui.<init>(ProjGui.java:49)
at WordsForSearch.<init>(WordsForSearch.java:18)
at ProjGui.main(ProjGui.java:91)
and heres the program. It has two classes
[import javax.swing.*;
public class ProjGui extends JFrame {
String std;
String[] ten1;
String[] ten2;
String[] nine1;
String[] eight1;
String[] eight2;
String[] seven1;
String[] six1;
String[] five1;
String[] four1;
String[] four2;
String[] three1;
String[] three2;
String[] three3;
private JTable table;
//static Scanner inputStream = null;
//static Scanner kb = new Scanner(System.in);
//int width;
//int length;
public ProjGui() {
getContentPane().setLayout(new GridLayout(1, 0, 0, 0));
table = new JTable();
table.setToolTipText("");
table.setColumnSelectionAllowed(true);
table.setCellSelectionEnabled(true);
table.setBorder(new BevelBorder(BevelBorder.LOWERED, SystemColor.controlHighlight, SystemColor.textHighlight, null, null));
table.setBackground(Color.WHITE);
table.setSelectionMode(ListSelectionModel.MULTIPLE _INTERVAL_SELECTION);
table.setModel(new DefaultTableModel(
new Object[][] {
{"g", "a", "b", ten2[9], ten2[8], ten2[7], ten2[6], ten2[5], ten2[4], ten2[3], ten2[2], ten2[1], ten2[0], "m", "n", "z", "a", "q", "b", "e"},
{"m", "f", "a", "j", "b", "v", "e", "j", "a", "s", "d", "h", "j", "s", four1[3], "a", "i", "n", "b", eight2[0]},
{"g", "y", eight2[7], "m", "l", "p", "o", "q", "e", "u", "z", "a", "o", "p", "e", four1[2], "c", "b", "e", eight2[1]},
{"l", "x", "e", eight2[6], "b", "n", "o", "d", "l", "p", "d", "m", "a", "p", "o", "l", four1[1], "g", "a", eight2[2]},
{ten1[0], "l", "h", "r", eight2[5], "t", "l", "l", "u", "l", "a", "m", "h", "c", "v", "a", "e", four1[0], "w", eight2[3]},
{ten1[1], "a", "s", "a", "g", eight2[4], "j", "u", "e", "s", "l", "e", "l", "t", "p", "o", "b", "s", "g", eight2[4]},
{ten1[2], "m", "n", "w", "u", "l", eight2[3], "r", "y", "g", "w", "s", "w", "a", "t", "d", "k", "t", "s", eight2[5]},
{ten1[3], "e", "a", "r", "r", "t", "m", eight2[2], "e", "o", "a", "k", "o", "c", "a", "l", "u", "n", "j", eight2[6]},
{ten1[4], "a", "m", "n", "e", "e", "e", "v", eight2[1], "o", "a", "i", "b", "o", "e", "a", "g", seven1[6], "d", eight2[7]},
{ten1[5], "v", "u", "j", "n", "c", "i", "u", "x", eight2[0], "g", "m", "a", "m", "m", "s", seven1[5], "u", "e", "l"},
{ten1[6], "c", four2[0], four2[1], four2[2], four2[3], "c", "o", "o", "b", eight2[6], "o", "v", "a", "a", seven1[4], "w", five1[5], "n", "a"},
{ten1[7], "u", "j", "a", "x", "l", "a", "e", "l", "y", "i", "b", "e", "c", seven1[3], "s", "x", five1[4], "v", "c"},
{ten1[8], "e", "h", "t", "z", "a", "r", "f", "p", "p", "n", "r", "e", seven1[2], "y", "o", "p", five1[3], "e", "y"},
{ten1[9], "k", "n", "h", "o", "n", three3[2], "o", "r", "o", "n", "o", seven1[1], "a", "o", "g", "v", five1[2], "u", "v"},
{"z", "j", "i", "a", "p", "o", three3[1], "u", "e", "w", "o", seven1[0], "h", "r", "g", "s", "h", six1[1], "y", "e"},
{"n", three1[0], three1[1], three1[2], "q", "w", three3[0], "r", "g", "l", "s", "t", "s", "t", "o", "e", "r", six1[0], "q", five1[4]},
{"p", "a", "m", "w", "k", "e", "b", "e", "n", "m", "r", "h", "e", "h", "m", "m", "i", "y", five1[3], "b"},
{"s", "u", "r", "j", "h", "t", "a", "v", "a", "e", "e", "e", three2[2], three2[1], three2[0], "j", "u", five1[2], "m", "v"},
{"f", "e", "e", "s", "g", "s", "h", "a", "f", "h", "p", "r", "h", "u", "o", "k", five1[1], "g", "d", "n"},
{"h", "z", eight1[7], eight1[6], eight1[5], eight1[4], eight1[3], eight1[2], eight1[1], eight1[0], "a", "s", "t", "r", "d", five1[0], "g", "a", "l", "j"},
},
new String[] {
"", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column"
}
) {
Class[] columnTypes = new Class[] {
String.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class
};
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
});
table.setForeground(Color.BLACK);
int column;
int row;
//table.getValueAt(row, column);
getContentPane().add(table);
}
public static void main(String[] args) {
WordsForSearch obj1 = new WordsForSearch();
obj1.getWords();
obj1.writeToFile();
ProjGui gui = new ProjGui();
gui.setVisible(true);
}
}
]
//That's the main class
//This is the child class that has all my objects...called WordsForSearch
[import javax.swing.*;
import java.util.*;
import java.awt.GridLayout;
import java.awt.Color;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import java.awt.SystemColor;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.util.Scanner;
import javax.swing.border.BevelBorder;
public class WordsForSearch extends ProjGui {
String first10;String sec10;String nineStr;String eightFi;
String eightSec; String sevenFi; String sixFi;String fiveFi;
String fourFi; String fourSec;String threeFi; String threeSec;
String threeTh;
public void getWords() {
first10 = JOptionPane.showInputDialog("What is the first 10 letter word");
first10= first10.replace("", " ").trim();
ten1 = first10.split(" ");
sec10 = JOptionPane.showInputDialog("What is the second 10 letter word?");
sec10= sec10.replace("", " ").trim();
ten2 = sec10.split(" ");
nineStr = JOptionPane.showInputDialog("What is the 9 letter word?");
nineStr= nineStr.replace("", " ").trim();
nine1 = nineStr.split(" ");
eightFi = JOptionPane.showInputDialog("What is the first 8 letter word?");
eightFi = eightFi.replace("", " ").trim();
eight1 = eightFi.split(" ");
eightSec = JOptionPane.showInputDialog("What is the second 8 letter word?");
eightSec = eightSec.replace("", " ").trim();
eight2 = eightSec.split(" ");
sevenFi = JOptionPane.showInputDialog("What is the 7 letter word?");
sevenFi = sevenFi.replace("", " ").trim();
seven1 = sevenFi.split(" ");
sixFi = JOptionPane.showInputDialog("What is the 6 letter word?");
sixFi = sixFi.replace("", " ").trim();
six1 = sixFi.split(" ");
fiveFi = JOptionPane.showInputDialog("What is the 5 letter word?");
fiveFi = fiveFi.replace("", " ").trim();
five1 = fiveFi.split(" ");
fourFi = JOptionPane.showInputDialog("What is the first 4 letter word?");
fourFi = fourFi.replace("", " ").trim();
four1 = fourFi.split(" ");
fourSec = JOptionPane.showInputDialog("What is the second 4 letter word?");
fourSec = fourSec.replace("", " ").trim();
four2 = fourSec.split(" ");
threeFi = JOptionPane.showInputDialog("What is the first 3 letter word?");
threeFi = threeFi.replace("", " ").trim();
three1 = threeFi.split(" ");
threeSec = JOptionPane.showInputDialog("What is the second 3 letter word?");
threeSec = threeSec.replace("", " ").trim();
three2 = threeSec.split(" ");
threeTh = JOptionPane.showInputDialog("What is the third 3 letter word?");
threeTh = threeTh.replace("", " ").trim();
three3 = threeTh.split(" ");
}
public void writeToFile() {
FileWriter fWriter = null;
BufferedWriter writer = null;
try {
fWriter = new FileWriter("IAFile.txt");
writer = new BufferedWriter(fWriter);
writer.write(first10);
writer.newLine();
writer.write(sec10);
writer.newLine();
writer.write(nineStr);
writer.newLine();
writer.write(eightFi);
writer.newLine();
writer.write(eightSec);
writer.newLine();
writer.write(sevenFi);
writer.newLine();
writer.write(sixFi);
writer.newLine();
writer.write(fiveFi);
writer.newLine();
writer.write(fourFi);
writer.newLine();
writer.write(fourSec);
writer.newLine();
writer.write(threeFi);
writer.newLine();
writer.write(threeSec);
writer.newLine();
writer.write(threeTh);
writer.close();
System.out.println("Your input was saved");
} catch (Exception e) {
System.out.println("File not Found please fix errors!");
}
}
}
]