Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom JTabbedPane event problem  RSS feed

 
mandlar suurla
Ranch Hand
Posts: 67
Debian Linux PHP
  • Mark post as helpful
  • send pies
  • 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


 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Debian Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah works, i dont know even myself why i wrote null
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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 !
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everybody does something silly which gives rise to an NPE occasionally.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
But the OP did have a working code from the Java tutorial.
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you never copied anything wrongly?
 
mandlar suurla
Ranch Hand
Posts: 67
Debian Linux PHP
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I do for learning. And I sometimes write things wrongly.
 
mandlar suurla
Ranch Hand
Posts: 67
Debian Linux PHP
  • Mark post as helpful
  • send pies
  • 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: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!