jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes wrong output and exception problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "wrong output and exception problem" Watch "wrong output and exception problem" New topic

wrong output and exception problem

oghenekaro EFEKODO
Ranch Hand

Joined: Oct 10, 2005
Posts: 56
need help in identifying what is wrong with my code especially the hypergeomeyric method which when ever i execute it,it display an understandable exception in command prompt.also the poisson method only display the correct result when r=0 but result when r=1 to n.thanks for ever listening hears.
David Nemeskey
Ranch Hand

Joined: Nov 08, 2006
Posts: 52

please describe what exceptions you get with which parameters! It would be much easier to help like that.

Anyway, I have run your code, and I got the following exception when trying the Hypergeometric Distribution:

A short inspection told me that NField (and the others as well: nField, rField, etc) are null. Please have a look at the GUI building code. NField is declared as:

It is redefined locally, so no wonder that the NField member in the class is null. Compare this with the field initialization for the Poisson tab:

These errors can be very annoying, but should not be hard to find. The exception above is very clear about what the problem is: a null reference in the actionPerformed method. So you should just find which reference is null. Using an IDE with a debugging option (nearly all of them) can help much, as it can show you which one is the culprit just by moving your mouse over them.
[ November 17, 2006: Message edited by: David Nemeskey ]
David Nemeskey
Ranch Hand

Joined: Nov 08, 2006
Posts: 52
Also, one other suggestion:
in the main method, you should call f.setVisible() as the last instruction.


You may remember, that according to the Swing threading model, all modifications to an already visible GUI must be run in the event dispatch thread. This applies to your program from the moment you call f.setVisible(). When I first ran your program, it just displayed an empty frame, as the c.add(cm) "did not make it" to my screen.

Please have a look at the Swing tutorial at Sun.
[ November 17, 2006: Message edited by: David Nemeskey ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
wood burning stoves
subject: wrong output and exception problem
It's not a secret anymore!