• 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

java.lang.NullPointerException in JInternalFrame

 
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have JFrame class with a JDeskPanel and a JPanel with some buttons.

I have JInternalFrame class that is called by a button in my JPanel.

The problem is that when execute the ActionPerformed I have receiving java.lang.NullPointerException.

Below little bit of classes.

JFrame:


And

And


Below is my JInternalFrame class:


Thanks in advance.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have receiving java.lang.NullPointerException.


Please copy the full text of the error message and paste it here. It has important info about the error.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and can you point out exactly which line in your code this was thrown from?
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, The exactly line of the error is line 5 "jdsktpane.add(execExmCardio);" of method "public void cadPacienteActionPerformed" above.

And this is the error log.


Thanks.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jdsktpane attribute is null.

In the constructor you initialise a local variable with the same name:

This is not the same variable.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After cgange "JDesktopPane jdsktpane = new JDesktopPane();" to "jdsktpane = new JDesktopPane();", the still de same in the same point.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, the problem still the same in the same point....
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You made the same mistake in the electrocardiogram constructor. I don't know whether that is the cause of the problem.

You have far too many fields in that class; you can probably make many of them local variables.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I made the changes and I don't receiving error again but my JInternalFrame are not loading. I believe that my problem are in my JInternalFrame class but I can't see where are the problem.

My Frame:


And my complete JInternalFrame:

Thanks.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you make a small, complete program that compiles and can be executed for testing?  Do no post the whole program.  Only post enough that will compile and execute to show the problem.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, my JFrame to test:


And my JInternalFrame:

In JFrame are only one button to call JInternalFrame and in InternalFrame are only one label to show.
Thanks.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't count as simple, not if you are using colours. Please only post what is relevant to throwing the exception.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code for IntFrmSmallTest is missing.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry by mistake.

JFrame:


JInternalFrame:

Thanks.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code declares two JFrames, one at line 16 and on at line 33.  The code then puts components in them separately and shows one of them.
Either do not extend JFrame on 16 or do not create a second JFrame on line 33.

The preferred fix is NOT to extend JFrame.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I made the changes but the problem still the same the jinternalframe are not be loaded.

Thanks.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't have a JInternalFrame in that code.

You do have a JDesktopPane, but you never add it to the GUI. Your GUI is the JFrame which contains a JPanel containing one JButton; you can click on the button but doing that just does some stuff unrelated to the components you have in your GUI.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now that I saw what you said the problem was solved.
Thanks and best regards.
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic