Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

? Trying to implement ListSelectionModel on an AbstractTableModel  RSS feed

 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting a null pointer exception on the following.

 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, good luck solving the problem because we can't help you:

a) we have no idea where you are getting the NPE
b) the posted code isn't compileable.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


>> Well, good luck solving the problem because we can't help you:
>> a) we have no idea where you are getting the NPE

My humble apologies here are the errors:
generated due to this line:

listSelectionModel = jTable1.getSelectionModel();

>> b) the posted code isn't compileable.

... and yes it is :-)



Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at air.CustomerUI.<init>(CustomerUI.java:28)
at air.CustomerUI$1.run(CustomerUI.java:96)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 1 second)



 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> >> b) the posted code isn't compileable.

< ... and yes it is :-)

compiles for you as you're the only one with 'CusTableModel',
so you'll have to fix it.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not even open for discussion?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
really, you post a bunch of custom code that only you can compile,
meaning our only option is to read it - and I for one am sick or reading code
that often is totally unrelated to the problem, so, if I cannot see the problem
by running the code, I ignore the post.

having said all that, the answer to your problem stands out like the proverbial 'dogs danglers'

I only mention it this way, so that when you have another problem, you won't waste everyone's
time, including your own, by posting non-compilable code.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, and thank you.


 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The NPE's stack trace tells you exactly on which line the problems occurs. In this case, it's the call to jTable1.getSelectionModel(), because jTable1 is null, because it's never initialized, because initComponents() (a horrible method obviously generated by an IDE...) is never called.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob.
Yes, initComponents(); was created by NetBeans.
Should I beware?

Geoff.

 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When modifying automatically generated code you should always beware. In this case you removed the call to initComponents(), and as a result your UI components remain null.

I myself (and many with me) prefer to not let any UI code be automatically generated but code everything ourselves. We have more control over what's happening, and since we wrote it ourselves we know what code can be changed/removed and what code cannot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!