Brian
Brian

Reputation: 2051

Trouble with populating JTable and JTextFields

I have various classes representing various types of program-genres (comedy, drama etc).

I have a text file filled with '-' seperated values that get read by a class called Processing and puts them into a LinkedList.

I have another class GUI_g that creates the GUI. It has 2 JTables. One for the list and 1 for the Channel. The JTable listTable gets filled from the linkedlist and whenever a user clicks on a row, the textfields' text changes accordingly.

I tried with 5 fields (Title, Genre and Duration, Actor, Director) and it worked, with the 3 textfields showing different text according to what row is clicked. However when I added all the needed values, an error comes up and no fields are filled.

I have two problems:

If it's a MusicVideo the cells are not filled up (as it should be) however it returns an error when copying data to the JTextFields The Snyopsis column remains empty and is not filled. Below are the classes (the ones mainly used). If you need others tell me and I'll upload.

GUI_g: http://pastebin.com/KsZBwgtR ProgramTableModel: http://pastebin.com/6Rc2bVxa Processing: http://pastebin.com/8f8iteVK Program: http://pastebin.com/NU3XGvM8

This is the error I get:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at GUI_g$1.mouseClicked(GUI_g.java:205)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
    at java.awt.Component.processMouseEvent(Component.java:6507)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6269)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4860)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4686)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4501)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2713)
    at java.awt.Component.dispatchEvent(Component.java:4686)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
    at java.awt.EventQueue.access$000(EventQueue.java:101)
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:680)
    at java.awt.EventQueue$4.run(EventQueue.java:678)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Image example:

enter image description here

Upvotes: 0

Views: 265

Answers (1)

Ozzy
Ozzy

Reputation: 8322

The problem is line 205 in your GUI_g class (as the compiler stated).

String actor = listTable.getValueAt(row, column+3).toString();

You didn't check or clean the input value before you tried to use the toString() method.

you can't use a method on a null value, of course.

You need to check all inputs (not just this one). Since you have a lot of fields you should make a helper method/class to do that for you and return a clean input.

If you just want to get around this one quickly, do this:

String actor = " ";
T input = listTable.getValueAt(row, column+3);
if (input != null) actor = input.toString();
return actor;

Replace 'T' with whatever object you were trying to check.

Upvotes: 1

Related Questions