• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField InputVerifier

 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Reader,
I have a class which extends JPanel, which in turns has a JTextField. I want to verify the input to JTextField using

In inputVerfier(comp) I have a JOptionPane and when JOptionPane gets executed I get a nullpointer exception and the program crushes and even JBuilder stop responding.(although I am not running the code from JBuilder)
Code for inputVerfier(String content)

I am wondering what is going wrong.
Thank you
Garandi
[ June 13, 2003: Message edited by: Garandi Garandi ]
 
Manish Hatwalne
Ranch Hand
Posts: 2591
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
USE this code instead and let us know if you still have a problem.

HTH,
- Manish
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is same is mine and this would NOT work either.
Garandi
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Manish
I think that the follwing code still have problem

//Because without the variable to store the return value of the (1) so (2) may still contain problem.
(1)Double.parseDouble(content);
(2)Double value = new Double(content);
Use the following code to substitution.
Double value = new Double(Double.parseDouble(content));
If the coding still have compiler error or logic error,please post it again
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just:
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris
You said the truth,but the following statement is within try block,so if only using Double value = new Double(content);
I concern that it does not throw exception
But after reading the following statement, it throw exception
if(value.doubleValue() <= 0)
So you can consider WHEN the exception throw,of course, it does not matter.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by siu chung man:
Chris
You said the truth,but the following statement is within try block,so if only using Double value = new Double(content);
I concern that it does not throw exception

It certainly will throw an exception if the String cannot be parsed. Read the javadocs for Double.
[ June 15, 2003: Message edited by: Chris Mathews ]
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is with

which is called inside the method and the method is called inside a inner class.
Thank you
Garandi
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It certainly will throw an exception if the String cannot be parsed.
Yes,I know,but it can not throw NumberFormatException
You may be missunderstanding what I want to express.
Do the input must be String so that it must convert successfully?
Except for the Null Pointer Exception
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the input is not a number I want it to throw an exception.
But the problem is with JOptionPane line in the code. I don't know why?
Thank you
Garandi
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by siu chung man:
Yes,I know,but it can not throw NumberFormatException
You may be missunderstanding what I want to express.
Do the input must be String so that it must convert successfully?
Except for the Null Pointer Exception

Why can't it? In fact it certainly does throw a NumberFormatException. See the javadocs, they clearly state that the Double(String s) constructor will throw a NumberFormatException if the String cannot be parsed.
Sorry for the hijack. :roll:
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris
yes,I read it.
But the problem is with JOptionPane line in the code. I don't know why?
I think that (this) can not refer to the top level window,so you should get the top level window object to that to show it out.(because you are using the JPanel in this class)
Please try it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic