<legend id='1T1Bm'><style id='1T1Bm'><dir id='1T1Bm'><q id='1T1Bm'></q></dir></style></legend>
  • <small id='1T1Bm'></small><noframes id='1T1Bm'>

    1. <i id='1T1Bm'><tr id='1T1Bm'><dt id='1T1Bm'><q id='1T1Bm'><span id='1T1Bm'><b id='1T1Bm'><form id='1T1Bm'><ins id='1T1Bm'></ins><ul id='1T1Bm'></ul><sub id='1T1Bm'></sub></form><legend id='1T1Bm'></legend><bdo id='1T1Bm'><pre id='1T1Bm'><center id='1T1Bm'></center></pre></bdo></b><th id='1T1Bm'></th></span></q></dt></tr></i><div id='1T1Bm'><tfoot id='1T1Bm'></tfoot><dl id='1T1Bm'><fieldset id='1T1Bm'></fieldset></dl></div>

          <bdo id='1T1Bm'></bdo><ul id='1T1Bm'></ul>
        <tfoot id='1T1Bm'></tfoot>
      1. 将十六进制字符串解析为整数会引发 NumberFormat

        时间:2023-10-01
      2. <legend id='xzm4S'><style id='xzm4S'><dir id='xzm4S'><q id='xzm4S'></q></dir></style></legend>
        <tfoot id='xzm4S'></tfoot>

        1. <i id='xzm4S'><tr id='xzm4S'><dt id='xzm4S'><q id='xzm4S'><span id='xzm4S'><b id='xzm4S'><form id='xzm4S'><ins id='xzm4S'></ins><ul id='xzm4S'></ul><sub id='xzm4S'></sub></form><legend id='xzm4S'></legend><bdo id='xzm4S'><pre id='xzm4S'><center id='xzm4S'></center></pre></bdo></b><th id='xzm4S'></th></span></q></dt></tr></i><div id='xzm4S'><tfoot id='xzm4S'></tfoot><dl id='xzm4S'><fieldset id='xzm4S'></fieldset></dl></div>

          <small id='xzm4S'></small><noframes id='xzm4S'>

              <bdo id='xzm4S'></bdo><ul id='xzm4S'></ul>
                    <tbody id='xzm4S'></tbody>
                  本文介绍了将十六进制字符串解析为整数会引发 NumberFormatException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  所以,在 Java 中,您知道如何像这样声明整数:

                  So, In Java, you know how you can declare integers like this:

                  int hex = 0x00ff00;
                  

                  我认为您应该能够逆转该过程.我有这个代码:

                  I thought that you should be able to reverse that process. I have this code:

                  Integer.valueOf(primary.getFullHex());
                  

                  其中 primary 是自定义 Color 类的对象.它的构造函数接受一个整数表示不透明度(0-99)和一个十六进制字符串(例如 00ff00).

                  where primary is an object of a custom Color class. It's constructor takes an Integer for opacity (0-99) and a hex String (e.g. 00ff00).

                  这是 getFullHex 方法:

                  public String getFullHex() {
                      return ("0x" + hex);
                  }
                  

                  当我调用此方法时,它会给出我的 NumberFormatException:

                  When I call this method it gives my this NumberFormatException:

                  java.lang.NumberFormatException: For input string: "0xff0000"
                  

                  我不明白发生了什么.谁能解释一下?

                  I can't understand what's going on. Can someone please explain?

                  推荐答案

                  这会有帮助吗?

                  Integer.parseInt("00ff00", 16)
                  

                  16 表示您应该将字符串解释为基于 16 的(十六进制).使用 2 可以解析二进制数,8 代表八进制.10 是默认值,解析十进制数.

                  16 means that you should interpret the string as 16-based (hexadecimal). By using 2 you can parse binary number, 8 stands for octal. 10 is default and parses decimal numbers.

                  在您的情况下, Integer.parseInt(primary.getFullHex(), 16) 将不起作用,因为 0x 前缀由 getFullHex() - 摆脱,你会没事的.

                  In your case Integer.parseInt(primary.getFullHex(), 16) won't work due to 0x prefix prepended by getFullHex() - get rid of and you'll be fine.

                  这篇关于将十六进制字符串解析为整数会引发 NumberFormatException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                      <tbody id='4PRno'></tbody>

                    <small id='4PRno'></small><noframes id='4PRno'>

                      <bdo id='4PRno'></bdo><ul id='4PRno'></ul>
                      <legend id='4PRno'><style id='4PRno'><dir id='4PRno'><q id='4PRno'></q></dir></style></legend>
                        <tfoot id='4PRno'></tfoot>

                          <i id='4PRno'><tr id='4PRno'><dt id='4PRno'><q id='4PRno'><span id='4PRno'><b id='4PRno'><form id='4PRno'><ins id='4PRno'></ins><ul id='4PRno'></ul><sub id='4PRno'></sub></form><legend id='4PRno'></legend><bdo id='4PRno'><pre id='4PRno'><center id='4PRno'></center></pre></bdo></b><th id='4PRno'></th></span></q></dt></tr></i><div id='4PRno'><tfoot id='4PRno'></tfoot><dl id='4PRno'><fieldset id='4PRno'></fieldset></dl></div>