ksoap passing a long value from an int

时间:2015-09-01 21:15:20

标签: java casting int long-integer ksoap

I'm trying to send some info to s webService. It requires a long value that I have to get from a EditText field:

If I do:

long nit; // on the Client class    
client.nit = 34546365755;

It works! But, if i get the value from the editText and convert it into an int, it does not. I've tried:

int cc = Integer.valueOf("xxx");
client.nit = Long.parseLong(cc);

and

Integer cc = Integer.valueOf("xx");
client.nit = cc.longValue();

I also found this method in an answer

public static long castToLong(Object o) {
    Number n = (Number) o;
    return n.longValue();
}

But it's still not working, unless I type some fake values. I'm lost, help!

1 个答案:

答案 0 :(得分:0)

因为您尝试使用错误的方法将整数值转换为long值。    Long.parseLong(str); 此方法需要字符串值。 试试这个:     Long.parseLong(string_value_of_edittext);