• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello i have that error in my application :Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Base_de_donnes.Utilisateur.table(Utilisateur.java:25)
at Base_de_donnes.Utilisateur.<init>(Utilisateur.java:19)
at Base_de_donnes.Utilisateur$9.run(Utilisateur.java:298)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
THIS IS MY code:


i have error in this method

and this is the method:

the problem is that the database did not appear in the JFram
please i need help and thanks
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Rnh

Please show us which line in your code is causing the exception; you can find the numbers from the stack trace. It might be line 25; if I go back and add code tags to your code, that will make the code look better () and might help you find where the problem is.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe this is the line that is causing the error:
If so, ask yourself where the variable jtable1 is ever declared and initialized.
 
azza guirat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnak you yes i have  looked in my code and i did not find any declaration
but i found this in the init conponents
jtable1.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}
           },
           new String [] {
               "Title 1", "Title 2", "Title 3", "Title 4", "Title 5"

how could i declare the jtable i don't know how . Plaese help me.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You declare the table the same way you declare any other variable. Probably as a variable local to that method.
If you are having that sort of difficulty, stop using an IDE and code everything by hand. Go back to the IDE when you are more experienced. The IDE is doing things automatically and you aren't seeing what is happening.
 
azza guirat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no this not what i mean jtable is the table which i made in the interface i think that is default initized  that's why i did not know how to initialize or should iinitialize the table which result fro Fro ResultTableModel
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try switching the table and initComponent method calls. Now you're trying to use jtable1 inside the table method, but it's most likely initialized inside the initComponents method. And if this code is generated by an IDE like I think it is, then initComponents will not try to use any non-UI fields like rs.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

azza guirat wrote:...jtable is the table which i made in the interface i think that is default initized  that's why i did not know how to initialize or should iinitialize the table which result fro Fro ResultTableModel


If I'm understanding you, you need to pass a reference to your JTable (jtable1) into Utilisateur from another class.  I don't exactly know how Swing works (I've only written one application in it) but this could be as simple as passing the reference through the constructor or setter, or more difficult, depending on the relationship of the class that initializes jtable1 to Utilisateur.  How does Utilisateur get called?
 
azza guirat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Utilisateur is my jframe  Form which Jtable1 is the noun of the table of utilisateurs and i want to show the database "utilisateur" in this  table but i can't. all the buttons works but the table doesn't work and i dont't know how to do that
i'm bloqued .it shows this error
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the class Utilisateur is supposed to be the JTable itself, then you don't need the variable "jtable1."  Change "jtable1" to "this" and see how it works.  The "this" keyword in Java is a way to reference that class you're currently executing.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Azza, did you already try my suggestion?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:Try switching the table and initComponent method calls. Now you're trying to use jtable1 inside the table method, but it's most likely initialized inside the initComponents method. And if this code is generated by an IDE like I think it is, then initComponents will not try to use any non-UI fields like rs.


So your theory is that the reason we can't see anything in initComponents is that it has been folded by the IDE?  It's certainly worth a shot, although I don't know how a local jtable1 variable is going to get into the table() method, since there doesn't appear to be a field called "jtable1."  Also, why does the class extend JTable if it isn't itself the JTable?

But regardless, it's an easy thing to do.  I'm curious if it will work.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh!  I know why it might work.  NetBeans has a habit of putting the class's fields at the bottom of the code, which is not shown.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. It's probably part of the ... at the bottom of the code snippet. I was wondering where you got the idea that jtable1 was a local variable since it was never declared in the provided code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic