Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Custom JTabbedPane event problem

 
Ranch Hand
Posts: 67
PHP Debian Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code is here but when i try to close tab it gives me NullPointerException, i cant find bug here, it seems right to me.

Code is mostly taken from Javas tutorial
http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TabComponentsDemoProject/src/components/TabComponentsDemo.java

http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TabComponentsDemoProject/src/components/ButtonTabComponent.java


 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mandlar suurla:
Code is here but when i try to close tab it gives me NullPointerException, i cant find bug here, it seems right to me.
[/CODE]



Your pane instance is null. You accept a pane reference in the constructor but you never assign it to the instance reference. In fact you are saying [code]this.pane=null;[/code] I wonder what you had in mind when you did it.

Anyway, change[code] this.pane=pane[/code] and that will fix your problem.
 
mandlar suurla
Ranch Hand
Posts: 67
PHP Debian Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah works, i dont know even myself why i wrote null
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mandlar suurla:
yeah works, i dont know even myself why i wrote null



How do you write your code? Do you use any IDE? If not I would strongly suggest you start using one. Any decent IDE allows you to set breakpoints and run your code in Debug mode so you can easily identify what is causing the NPE.
NPE is almost invariably because of programming errors. No offence, but posting NPE in the forum is kind of childish !
 
Marshal
Posts: 76067
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everybody does something silly which gives rise to an NPE occasionally.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
But the OP did have a working code from the Java tutorial.
 
Campbell Ritchie
Marshal
Posts: 76067
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you never copied anything wrongly?
 
mandlar suurla
Ranch Hand
Posts: 67
PHP Debian Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually i didnt copy it because it was meant to be for learning. As I write code i focus on code more.
 
Campbell Ritchie
Marshal
Posts: 76067
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I do for learning. And I sometimes write things wrongly.
 
mandlar suurla
Ranch Hand
Posts: 67
PHP Debian Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Maneesh Godbole:


How do you write your code? Do you use any IDE? If not I would strongly suggest you start using one. Any decent IDE allows you to set breakpoints and run your code in Debug mode so you can easily identify what is causing the NPE.
NPE is almost invariably because of programming errors. No offence, but posting NPE in the forum is kind of childish !


I use Eclipse but i dont know how to debug swing app, i know how to debug console program but not swing.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mandlar suurla:

I use Eclipse but i dont know how to debug swing app, i know how to debug console program but not swing.



It doesn't matter what the code does. For eclipse it is just code. The stack trace gives you information on what code line number the exception originated along with the class name. Based on that you can decide where to set the break point and inspect variables.

This article contains some nice tips for debugging in eclipse.
http://www-128.ibm.com/developerworks/opensource/library/os-ecbug/
[ July 14, 2008: Message edited by: Maneesh Godbole ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic