下面这两句为什么会抛出异常呢?
String str="0x00ffff00";
try
{
int rgb=Integer.parseInt(str);
}
catch(Exception e)
{
System.out.println("error "+e.getmessage());
}
执行的时候就会出现异常~~
String str="0x00ffff00";
try
{
int rgb=Integer.parseInt(str);
}
catch(Exception e)
{
System.out.println("error "+e.getmessage());
}
执行的时候就会出现异常~~
解决方案 »
- Java Swing等其他 c/s架构 中的通信一般使用什么协议?
- Java连接代理验证用户名密码后,怎样返回用户名密码是否正确?
- ThreadLocal中弱引用的疑惑
- excel文件打开后再导入数据报错 能直接覆盖吗
- 关于java模拟ie登陆web的问题?
- 关于 visual editor 中的 alignment tool
- call和execution有啥区别?
- java里如何调用DLL?最好能给范例。
- 小弟用JB7出来问题了,哪位大虾来看看,帮帮我!!!!!!!!!!!
- How to use trees 问题
- 数据库连接的问题,请问高手该程序还有缺陷吗?
- 哪本数据结构的书性价比高??????
Integer i=null;
try{
i=Integer.decode(sStr);
}catch(NumberFormatException e){
e.printStackTrace(System.err);
}
System.out.println("pring i="+i.intValue());
parseInt("473", 10) returns 473
parseInt("-0", 10) returns 0
parseInt("-FF", 16) returns -255
parseInt("1100110", 2) returns 102
parseInt("2147483647", 10) returns 2147483647
parseInt("-2147483648", 10) returns -2147483648
parseInt("2147483648", 10) throws a NumberFormatException
parseInt("99", 8) throws a NumberFormatException
parseInt("Kona", 10) throws a NumberFormatException
parseInt("Kona", 27) returns 411787
String str="00ffff00"
Integer.parseInt(str,16);
int radix)
throws NumberFormatExceptionParses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of the specified radix (as determined by whether Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned.
An exception of type NumberFormatException is thrown if any of the following situations occurs: The first argument is null or is a string of length zero.
The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX.
Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign '-' ('\u002D') provided that the string is longer than length 1.
The value represented by the string is not a value of type int.
好象还是抛异常
不是"0x00ffff00",而是"00ffff00"
后面已经有个16可以表征进制了
的确也可以实现,但是decode()调用valueOf(),valueOf()调用parseInt(),所以你那样做是不是舍近求远啊?呵呵。感觉能养成读源码的习惯很不错
int i=0x00ffff00;
这样有什么问题么?
为什么要转换,0x00ffff00就不是int了吗?
1 J2ME没有Integer.decode()这个函数
2 用Integer.parseInt(str,16)还是抛出异常。
我要的str转成16进制必须以"0x"开头,要不然图像不能显示。呵呵~~大家再费费心帮我想想呗~~
谢谢
对了,现在还能增分吗?呵呵~~我可以加分啊~~