数值超出范围

发布于 2024-11-01 01:29:49 字数 940 浏览 0 评论 0原文

当我保存数据时,它给出错误,即数值超出范围 我已将这 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断念 2024-11-08 01:29:49

您没有告诉我们 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 a double.

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.

沒落の蓅哖 2024-11-08 01:29:49

好吧,应用程序应该告诉您错误所在的字段/行。

但是,就像 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文