You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by mm...@me.com.INVALID on 2019/06/25 23:20:46 UTC
JTable - Null Pointer - GUI editor
I placed a JTable, on a JScrollPane on a JInternalFrame, using the default DefaultTableModel.
When I try and load data into the model I get a java.lang.NullPointerException.
scriptTable.setValueAt(num, row, 2);
The table is initialized in the constructor method InitComponents.
Any idea what I’m doing wrong?
Best Regards,
Michael
Re: JTable - Null Pointer - GUI editor
Posted by Bayless <bk...@cox.net>.
The code you show does not populate the data vector so it has no rows
unless you just haven't shown where you do that. You can't set a value
in a row that does not exist, thus null probably. Also num or row could
be null. Finally, your column numbers in the setValueAt lines do not
agree with your defined columns.
Anyway as someone suggested earlier, Set a breakpoint at the offending
line and find out what is null. If that doesn't show it then precede
with get the data vector from the model and check it.
Bayless
On 6/26/19 12:45 PM, mmouer@me.com wrote:
> This is the generated code:
>
> private void initComponents() {
>
> jScrollPane1 = new javax.swing.JScrollPane();
> scriptTable = new javax.swing.JTable();
>
> setSize(new java.awt.Dimension(200, 200));
>
> scriptTable.setModel(new javax.swing.table.DefaultTableModel(
> new Object [][] {
>
> },
> new String [] {
> "Number", "Name", "Dose", "Instructions", "Date
> Filled", "Date to Refill", "Date to Renew", "Date Expires”
> }
> ));
> jScrollPane1.setViewportView(scriptTable);
>
> This is my code where I use it:
>
> scriptTable.getModel().setValueAt(num, row, 2); NULL POINTER HERE
> scriptTable.getModel().setValueAt(nam, row, 3);
> scriptTable.getModel().setValueAt(dose, row, 4);
> scriptTable.getModel().setValueAt(instruc, row, 5);
> scriptTable.getModel().setValueAt(filled, row, 6);
> scriptTable.getModel().setValueAt(tofill, row, 7);
> scriptTable.getModel().setValueAt(torenew, row, 8);
> scriptTable.getModel().setValueAt(expires, row, 9);
>
> Best Regards,
>
> Michael
> On Jun 26, 2019, 4:33 AM -0700, Bayless <bk...@cox.net>, wrote:
>>
>> Or maybe you have not created the model or supplied it with starting
>> data vector.
>>
>> Bayless
>>
>>
>> On 6/26/19 12:42 AM, Helmut Leininger wrote:
>>>
>>> Hi Michael,
>>>
>>> without more information it is very difficult to say. It could be
>>> that either scriptTable, num, or row is not set.
>>>
>>> I would try to use the debugger to find out.
>>>
>>> Helmut
>>>
>>> Am 26.06.2019 um 01:20 schrieb mmouer@me.com.INVALID:
>>>> I placed a JTable, on a JScrollPane on a JInternalFrame, using the
>>>> default DefaultTableModel.
>>>>
>>>> When I try and load data into the model I get a
>>>> java.lang.NullPointerException.
>>>>
>>>> scriptTable.setValueAt(num, row, 2);
>>>>
>>>> The table is initialized in the constructor method InitComponents.
>>>>
>>>> Any idea what I’m doing wrong?
>>>>
>>>> Best Regards,
>>>>
>>>> Michael
Re: JTable - Null Pointer - GUI editor
Posted by Helmut Leininger <h....@gmx.at>.
Michael,
I can execute it without problems., initialize for PrescriptionTable is
executed when it is created (from the menu Display/Prescriptons)
What did you specifiy as Main Class? It should be PrescriptionDisplay
Rergards
Am 27.06.2019 um 18:20 schrieb mmouer@me.com:
> Here it is.
>
> Best Regards,
>
> Michael
> On Jun 27, 2019, 8:32 AM -0700, Helmut Leininger <h....@gmx.at>,
> wrote:
>>
>> somewhere in the cloud (Dropbox, ....) or zip it and send me.
>>
>>
>> Am 27.06.2019 um 17:26 schrieb mmouer@me.com:
>>> Debugger says different.
>>>
>>> Where can I upload it?
>
>>>
>>> Best Regards,
>>>
>>> Michael
>>> On Jun 27, 2019, 8:24 AM -0700, Helmut Leininger
>>> <h....@gmx.at>, wrote:
>>>>
>>>> Michael,
>>>>
>>>> I am sorry, but I do not believe it. If you have "new NewJFrame()"
>>>> somewhere and you execute it, the constructor gets executed, too.
>>>> If not, You made an error (not calling new NewJFrame())
>>>>
>>>> Upload (or post) the whole program.
>>>>
>>>> Regards
>>>>
>>>> Am 27.06.2019 um 17:17 schrieb mmouer@me.com:
>>>>> All well in good but the problem is:
>>>>>
>>>>> initComponents(); is not being executed.
>>>>>
>>>>> The program goes right to my code bypassing the constructor and
>>>>> generated code.
>>>>>
>>>>> Best Regards,
>>>>>
>>>>> Michael
>>>>> On Jun 26, 2019, 11:50 PM -0700, Helmut Leininger
>>>>> <h....@gmx.at>, wrote:
>>>>>>
>>>>>> Michael,
>>>>>>
>>>>>> I assume you have created your GUI by New JFrame Form", right? At
>>>>>> least, I hope so.
>>>>>>
>>>>>> if you look at main() you will find something like:
>>>>>> new NewJFrame() ...
>>>>>>
>>>>>> NewJFrame ist the name you have given during the creation of your
>>>>>> class / form. This creates the form and first executes its
>>>>>> Constructor (public NewJFrame()). In this constructor, the first
>>>>>> is the call for initialize() (which does all initialization and
>>>>>> creation of the objects). If you want to add your personal
>>>>>> initializations, you would have to do this after initialize(),
>>>>>> probably in the same Constructor.
>>>>>>
>>>>>> If you are not sure about how to create GUI with or without
>>>>>> Netbeans, you will find several tutorials / videos in the Internet.
>>>>>>
>>>>>> Regards
>>>>>> Helmut
>>>>>>
>>>>>> Am 26.06.2019 um 21:21 schrieb mmouer@me.com:
>>>>>>> Thanks Helmut,
>>>>>>>
>>>>>>> I did use the debugger, first time for everything, and I found
>>>>>>> the initcomponents() is not being executed. I am under the
>>>>>>> impression that it is handled by NetBeans.
>>>>>>>
>>>>>>> I call the class:
>>>>>>>
>>>>>>> displays.PresciptionTable scripts = new
>>>>>>> displays.PrescriptionTable();
>>>>>>>
>>>>>>> Best Regards,
>>>>>>>
>>>>>>> Michael
>>>>>>> On Jun 26, 2019, 12:02 PM -0700, Helmut Leininger
>>>>>>> <hl...@gmx.at>, wrote:
>>>>>>>> Michael,
>>>>>>>> I strongly recommend to use the debugger. This will most
>>>>>>>> probably be the most efficient method to locate tje problem.
>>>>>>>>
>>>>>>>> - set a breakpoint on the line causing the ecception
>>>>>>>> - run the program with Debug
>>>>>>>> - when the program stops at the breakpoint inspect the variables
>>>>>>>>
>>>>>>>> As alternative you would have to print out every variable or
>>>>>>>> uplpad the whole program.
>>>>>>>>
>>>>>>>> Regards
>>>>>>>> Helmut
>>>>>>>>
>>>>>>>> Am 26. Juni 2019 20:15:00 MESZ schrieb mmouer@me.com:
>>>>>>>>
>>>>>>>>> did you initzialize num and row ?
>>>>>>>>>
>>>>>>>>> Yes I tried both 0 & 1. I used System.out.println(num) and
>>>>>>>>> it contains data.
>>>>>>>>>
>>>>>>>>> scriptTable.setModel(new javax.swing.table.DefaultTableModel(
>>>>>>>>>
>>>>>>>>> new Object [][] {
>>>>>>>>>
>>>>>>>>> {null, null, null, null, null, null, null,
>>>>>>>>> null},
>>>>>>>>>
>>>>>>>>> {null, null, null, null, null, null, null,
>>>>>>>>> null},
>>>>>>>>>
>>>>>>>>> {null, null, null, null, null, null, null,
>>>>>>>>> null},
>>>>>>>>>
>>>>>>>>> {null, null, null, null, null, null, null,
>>>>>>>>> null}
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> Same problem and this code is generated by NetBeans
>>>>>>>>>
>>>>>>>>
>>>>>>>> Best Regards,
>>>>>>>>
>>>>>>>> Michael
>>>>>>>> On Jun 26, 2019, 11:02 AM -0700, Helmut Leininger
>>>>>>>> <h....@gmx.at>, wrote:
>>>>>>>>>
>>>>>>>>> Once again:
>>>>>>>>>
>>>>>>>>> did you initzialize num and row ?
>>>>>>>>>
>>>>>>>>> When I design your example, I get:
>>>>>>>>>
>>>>>>>>> ...
>>>>>>>>> scriptTable.setModel(new javax.swing.table.DefaultTableModel(
>>>>>>>>> new Object [][] {
>>>>>>>>> {null, null, null, null},
>>>>>>>>> {null, null, null, null},
>>>>>>>>> {null, null, null, null},
>>>>>>>>> {null, null, null, null}
>>>>>>>>> },
>>>>>>>>> new String [] {
>>>>>>>>> "Title 1", "Title 2", "Title 3", "Title 4"
>>>>>>>>> }
>>>>>>>>> ));
>>>>>>>>> ...
>>>>>>>>>
>>>>>>>>> Where are your nulls for new Object[][] ?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Helmut
>>>>>>>>>
>>>>>>>>> Am 26.06.2019 um 19:45 schrieb mmouer@me.com.INVALID:
>>>>>>>>>> scriptTable.getModel().setValueAt(num, row, 2)
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail
>>>>>>>> gesendet.
Re: JTable - Null Pointer - GUI editor
Posted by Helmut Leininger <h....@gmx.at>.
Michael,
I am sorry, but I do not believe it. If you have "new NewJFrame()"
somewhere and you execute it, the constructor gets executed, too. If
not, You made an error (not calling new NewJFrame())
Upload (or post) the whole program.
Regards
Am 27.06.2019 um 17:17 schrieb mmouer@me.com:
> All well in good but the problem is:
>
> initComponents(); is not being executed.
>
> The program goes right to my code bypassing the constructor and
> generated code.
>
> Best Regards,
>
> Michael
> On Jun 26, 2019, 11:50 PM -0700, Helmut Leininger
> <h....@gmx.at>, wrote:
>>
>> Michael,
>>
>> I assume you have created your GUI by New JFrame Form", right? At
>> least, I hope so.
>>
>> if you look at main() you will find something like:
>> new NewJFrame() ...
>>
>> NewJFrame ist the name you have given during the creation of your
>> class / form. This creates the form and first executes its
>> Constructor (public NewJFrame()). In this constructor, the first is
>> the call for initialize() (which does all initialization and creation
>> of the objects). If you want to add your personal initializations,
>> you would have to do this after initialize(), probably in the same
>> Constructor.
>>
>> If you are not sure about how to create GUI with or without Netbeans,
>> you will find several tutorials / videos in the Internet.
>>
>> Regards
>> Helmut
>>
>> Am 26.06.2019 um 21:21 schrieb mmouer@me.com:
>>> Thanks Helmut,
>>>
>>> I did use the debugger, first time for everything, and I found the
>>> initcomponents() is not being executed. I am under the impression
>>> that it is handled by NetBeans.
>>>
>>> I call the class:
>>>
>>> displays.PresciptionTable scripts = new displays.PrescriptionTable();
>>>
>>> Best Regards,
>>>
>>> Michael
>>> On Jun 26, 2019, 12:02 PM -0700, Helmut Leininger <hl...@gmx.at>, wrote:
>>>> Michael,
>>>> I strongly recommend to use the debugger. This will most probably
>>>> be the most efficient method to locate tje problem.
>>>>
>>>> - set a breakpoint on the line causing the ecception
>>>> - run the program with Debug
>>>> - when the program stops at the breakpoint inspect the variables
>>>>
>>>> As alternative you would have to print out every variable or uplpad
>>>> the whole program.
>>>>
>>>> Regards
>>>> Helmut
>>>>
>>>> Am 26. Juni 2019 20:15:00 MESZ schrieb mmouer@me.com:
>>>>
>>>>> did you initzialize num and row ?
>>>>>
>>>>> Yes I tried both 0 & 1. I used System.out.println(num) and it
>>>>> contains data.
>>>>>
>>>>> scriptTable.setModel(new javax.swing.table.DefaultTableModel(
>>>>>
>>>>> new Object [][] {
>>>>>
>>>>> {null, null, null, null, null, null, null, null},
>>>>>
>>>>> {null, null, null, null, null, null, null, null},
>>>>>
>>>>> {null, null, null, null, null, null, null, null},
>>>>>
>>>>> {null, null, null, null, null, null, null, null}
>>>>>
>>>>> }
>>>>>
>>>>> Same problem and this code is generated by NetBeans
>>>>>
>>>>
>>>> Best Regards,
>>>>
>>>> Michael
>>>> On Jun 26, 2019, 11:02 AM -0700, Helmut Leininger
>>>> <h....@gmx.at>, wrote:
>>>>>
>>>>> Once again:
>>>>>
>>>>> did you initzialize num and row ?
>>>>>
>>>>> When I design your example, I get:
>>>>>
>>>>> ...
>>>>> scriptTable.setModel(new javax.swing.table.DefaultTableModel(
>>>>> new Object [][] {
>>>>> {null, null, null, null},
>>>>> {null, null, null, null},
>>>>> {null, null, null, null},
>>>>> {null, null, null, null}
>>>>> },
>>>>> new String [] {
>>>>> "Title 1", "Title 2", "Title 3", "Title 4"
>>>>> }
>>>>> ));
>>>>> ...
>>>>>
>>>>> Where are your nulls for new Object[][] ?
>>>>>
>>>>>
>>>>> Helmut
>>>>>
>>>>> Am 26.06.2019 um 19:45 schrieb mmouer@me.com.INVALID:
>>>>>> scriptTable.getModel().setValueAt(num, row, 2)
>>>>
>>>>
>>>> --
>>>> Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.
Re: JTable - Null Pointer - GUI editor
Posted by Helmut Leininger <h....@gmx.at>.
Michael,
I assume you have created your GUI by New JFrame Form", right? At
least, I hope so.
if you look at main() you will find something like:
new NewJFrame() ...
NewJFrame ist the name you have given during the creation of your class
/ form. This creates the form and first executes its Constructor (public
NewJFrame()). In this constructor, the first is the call for
initialize() (which does all initialization and creation of the
objects). If you want to add your personal initializations, you would
have to do this after initialize(), probably in the same Constructor.
If you are not sure about how to create GUI with or without Netbeans,
you will find several tutorials / videos in the Internet.
Regards
Helmut
Am 26.06.2019 um 21:21 schrieb mmouer@me.com:
> Thanks Helmut,
>
> I did use the debugger, first time for everything, and I found the
> initcomponents() is not being executed. I am under the impression that
> it is handled by NetBeans.
>
> I call the class:
>
> displays.PresciptionTable scripts = new displays.PrescriptionTable();
>
> Best Regards,
>
> Michael
> On Jun 26, 2019, 12:02 PM -0700, Helmut Leininger <hl...@gmx.at>, wrote:
>> Michael,
>> I strongly recommend to use the debugger. This will most probably be
>> the most efficient method to locate tje problem.
>>
>> - set a breakpoint on the line causing the ecception
>> - run the program with Debug
>> - when the program stops at the breakpoint inspect the variables
>>
>> As alternative you would have to print out every variable or uplpad
>> the whole program.
>>
>> Regards
>> Helmut
>>
>> Am 26. Juni 2019 20:15:00 MESZ schrieb mmouer@me.com:
>>
>>> did you initzialize num and row ?
>>>
>>> Yes I tried both 0 & 1. I used System.out.println(num) and it
>>> contains data.
>>>
>>> scriptTable.setModel(new javax.swing.table.DefaultTableModel(
>>>
>>> new Object [][] {
>>>
>>> {null, null, null, null, null, null, null, null},
>>>
>>> {null, null, null, null, null, null, null, null},
>>>
>>> {null, null, null, null, null, null, null, null},
>>>
>>> {null, null, null, null, null, null, null, null}
>>>
>>> }
>>>
>>> Same problem and this code is generated by NetBeans
>>>
>>
>> Best Regards,
>>
>> Michael
>> On Jun 26, 2019, 11:02 AM -0700, Helmut Leininger
>> <h....@gmx.at>, wrote:
>>>
>>> Once again:
>>>
>>> did you initzialize num and row ?
>>>
>>> When I design your example, I get:
>>>
>>> ...
>>> scriptTable.setModel(new javax.swing.table.DefaultTableModel(
>>> new Object [][] {
>>> {null, null, null, null},
>>> {null, null, null, null},
>>> {null, null, null, null},
>>> {null, null, null, null}
>>> },
>>> new String [] {
>>> "Title 1", "Title 2", "Title 3", "Title 4"
>>> }
>>> ));
>>> ...
>>>
>>> Where are your nulls for new Object[][] ?
>>>
>>>
>>> Helmut
>>>
>>> Am 26.06.2019 um 19:45 schrieb mmouer@me.com.INVALID:
>>>> scriptTable.getModel().setValueAt(num, row, 2)
>>
>>
>> --
>> Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.
Re: JTable - Null Pointer - GUI editor
Posted by Helmut Leininger <h....@gmx.at>.
Once again:
did you initzialize num and row ?
When I design your example, I get:
...
scriptTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
...
Where are your nulls for new Object[][] ?
Helmut
Am 26.06.2019 um 19:45 schrieb mmouer@me.com.INVALID:
> scriptTable.getModel().setValueAt(num, row, 2)
Re: JTable - Null Pointer - GUI editor
Posted by mm...@me.com.INVALID.
This is the generated code:
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
scriptTable = new javax.swing.JTable();
setSize(new java.awt.Dimension(200, 200));
scriptTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Number", "Name", "Dose", "Instructions", "Date Filled", "Date to Refill", "Date to Renew", "Date Expires”
}
));
jScrollPane1.setViewportView(scriptTable);
This is my code where I use it:
scriptTable.getModel().setValueAt(num, row, 2); NULL POINTER HERE
scriptTable.getModel().setValueAt(nam, row, 3);
scriptTable.getModel().setValueAt(dose, row, 4);
scriptTable.getModel().setValueAt(instruc, row, 5);
scriptTable.getModel().setValueAt(filled, row, 6);
scriptTable.getModel().setValueAt(tofill, row, 7);
scriptTable.getModel().setValueAt(torenew, row, 8);
scriptTable.getModel().setValueAt(expires, row, 9);
Best Regards,
Michael
On Jun 26, 2019, 4:33 AM -0700, Bayless <bk...@cox.net>, wrote:
> Or maybe you have not created the model or supplied it with starting data vector.
> Bayless
>
> On 6/26/19 12:42 AM, Helmut Leininger wrote:
> > Hi Michael,
> > without more information it is very difficult to say. It could be that either scriptTable, num, or row is not set.
> > I would try to use the debugger to find out.
> > Helmut
> > Am 26.06.2019 um 01:20 schrieb mmouer@me.com.INVALID:
> > > I placed a JTable, on a JScrollPane on a JInternalFrame, using the default DefaultTableModel.
> > >
> > > When I try and load data into the model I get a java.lang.NullPointerException.
> > >
> > > scriptTable.setValueAt(num, row, 2);
> > >
> > > The table is initialized in the constructor method InitComponents.
> > >
> > > Any idea what I’m doing wrong?
> > >
> > > Best Regards,
> > >
> > > Michael
Re: JTable - Null Pointer - GUI editor
Posted by Bayless <bk...@cox.net>.
Or maybe you have not created the model or supplied it with starting
data vector.
Bayless
On 6/26/19 12:42 AM, Helmut Leininger wrote:
>
> Hi Michael,
>
> without more information it is very difficult to say. It could be that
> either scriptTable, num, or row is not set.
>
> I would try to use the debugger to find out.
>
> Helmut
>
> Am 26.06.2019 um 01:20 schrieb mmouer@me.com.INVALID:
>> I placed a JTable, on a JScrollPane on a JInternalFrame, using the
>> default DefaultTableModel.
>>
>> When I try and load data into the model I get a
>> java.lang.NullPointerException.
>>
>> scriptTable.setValueAt(num, row, 2);
>>
>> The table is initialized in the constructor method InitComponents.
>>
>> Any idea what I’m doing wrong?
>>
>> Best Regards,
>>
>> Michael
Re: JTable - Null Pointer - GUI editor
Posted by Helmut Leininger <h....@gmx.at>.
Hi Michael,
without more information it is very difficult to say. It could be that
either scriptTable, num, or row is not set.
I would try to use the debugger to find out.
Helmut
Am 26.06.2019 um 01:20 schrieb mmouer@me.com.INVALID:
> I placed a JTable, on a JScrollPane on a JInternalFrame, using the
> default DefaultTableModel.
>
> When I try and load data into the model I get a
> java.lang.NullPointerException.
>
> scriptTable.setValueAt(num, row, 2);
>
> The table is initialized in the constructor method InitComponents.
>
> Any idea what I’m doing wrong?
>
> Best Regards,
>
> Michael