• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A problem adding a row in JTable using a button

 
hany hashemi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
I have a Jtable which is filled by the data related to MySql table.I added a button and i want the JTable to add a row while i am pressing the Insert button.
This is a part of my code.



I will be appreciative if somebody can help me solving this problem.
Thanks
Hany
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hany hashemi wrote:Hi everybody,
I have a Jtable which is filled by the data related to MySql table.I added a button and i want the JTable to add a row while i am pressing the Insert button.
This is a part of my code.



I will be appreciative if somebody can help me solving this problem.


I can't really help you solve "this problem" because you didn't actually say you had a problem. Perhaps you should describe how your code behaves differently from how you expect.

I will mention that you shouldn't have to call fireTableStructureChanged because you are using DefaultTableModel and its methods (such as addRow) fire events automatically.

Are you sure that your addNewRow method is even being called? If you put a println in there do you see any output?
 
hany hashemi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use the println and i saw that addNewRow method was called.I also comment the line related to fire a table but after pressing the insert button ,instead of adding a new row at the bottom of my table , i faced to these massages:
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you initialize your table model?
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If you can post the complete code then we would be able to pin point to the problem.

We have to know when that action is called? How many columns does your table hold? etc.,

Can you insert the code please.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The complete code is not necessary. We already know from the stack trace that one field in this code is null:

Since item is a newly created Vector that can't be null, and the only other variable that is dereferenced here is model. So that tells me that model == null, probably because it was only declared and never initialized.
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope that in the stack trace we will get "caused by".

By the line number in the trace if we can get hold of the line number that caused nullpointerexception. From the line we can see what is null.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic