数值超出范围
当我保存数据时,它给出错误,即数值超出范围 我已将这 3 个字段作为 MS ACCESS DB 中的数据类型编号,
我的手机号码为 4343242434,我为此编写的代码是:
double mno= Long.parseLong(tfmno.getText());
len = tfmno.getText().length();
if(len!=10) {
JOptionPane.showMessageDialog(null,"Enter The 10 Digit Mobile No","Error",JOptionPane.ERROR_MESSAGE);
return;
}
我的 pin 码为:2222222,我的 pin 码代码为:
i
nt pincode=Integer.parseInt(tfpcd.getText());
len1 = tfpcd.getText().length();
if(len1!=7) {
JOptionPane.showMessageDialog(null,"Enter The 7 Digit Pin Code","Error",JOptionPane.ERROR_MESSAGE);
return;
}
和 i电话号码为:2222333,我的代码是:
int tele=Integer.parseInt(tftele.getText());
len2 = tftele.getText().length();
if(len2!=7){
JOptionPane.showMessageDialog(null,"Enter The 7 Digit Telephone No","Error",JOptionPane.ERROR_MESSAGE);
return;
}
告诉我哪个值正在执行,我应该做什么
when i am saving the data its giving the error i.e NUMERIC VALUE OUT OF RANGE
I HAVE TAKEN THIS 3 FIELD AS DATATYPE NUMBER IN MS ACCESS DB
i was taken the mobile no as 4343242434 and i have written code for this is:
double mno= Long.parseLong(tfmno.getText());
len = tfmno.getText().length();
if(len!=10) {
JOptionPane.showMessageDialog(null,"Enter The 10 Digit Mobile No","Error",JOptionPane.ERROR_MESSAGE);
return;
}
and i was taken the pin code as:2222222 and my code for pincode is:
i
nt pincode=Integer.parseInt(tfpcd.getText());
len1 = tfpcd.getText().length();
if(len1!=7) {
JOptionPane.showMessageDialog(null,"Enter The 7 Digit Pin Code","Error",JOptionPane.ERROR_MESSAGE);
return;
}
and i was taken the telephone no as:2222333 and my code for this is:
int tele=Integer.parseInt(tftele.getText());
len2 = tftele.getText().length();
if(len2!=7){
JOptionPane.showMessageDialog(null,"Enter The 7 Digit Telephone No","Error",JOptionPane.ERROR_MESSAGE);
return;
}
tell me which value is exeeding and what should i do instead
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有告诉我们 tftele 是什么,但从调用的方法来看,我猜测它是一个 JTextField。
如果是这样,您的问题是在第一个示例中,您正在获取
long
值并分配给double
。double
是双精度浮点值,因此使用大量 64 位分配的内存来存储小数位后的值。将您的值存储在 double 中是没有意义的,特别是在它被解析为 long 之后(任何小数位都会引发异常)。我相信您的代码应该使用
long
值,因为您将其解析为 long。另外,请考虑在执行 X.parseX(text); 时捕获 NumberFormatException;也有陈述;以防万一您的用户在文本字段中键入非数字值。
You didn't tell us what tftele was, but from the methods invoked, I'm going to guess it's a JTextField.
If so, your problem is that in the first example you are taking your
long
value and assigning to adouble
.A
double
is a double-precision floating-point value, and as such uses a lot of it's 64-bits of allocated memory for storing values after the decimal place. There is no point in storing your value in a double, espessially after it has been parsed as a long (any decimal place would throw an exception anyways).I believe that your code should use a
long
value since you parsed it as a long.Also, think about catching a NumberFormatException when you do the X.parseX(text); statements too; just in case your users type non-numeric values for the text field.
好吧,应用程序应该告诉您错误所在的字段/行。
但是,就像 Jack 已经告诉您的那样,可能是这一行:
double mno= Long.parseLong(tfmno.getText());
顺便说一句,为什么不将值存储为文本?
Well, the application should tell you which field/line the error is in.
However, like Jack told you already, it's probably this line:
double mno= Long.parseLong(tfmno.getText());
Btw, why don't you store the values as text?