开发者

numeric value out of range

开发者 https://www.devze.com 2023-02-24 04:09 出处:网络
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

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 wha开发者_JAVA百科t should i do instead


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消