How to remove this issue about NumberFormatException?

Discussion in 'Java' started by bluestar, Jan 29, 2013.

  1. bluestar

    bluestar Guest

    Hi, all:

    I am rookie for coding java and I have one question about queue
    class

    I use one queue class: ArrayBlockingQueue to save/get my data

    I read some data from HW and save into one ArrayBlockingQueue, and
    then get from this ArrayBlockingQueue when needing. But it has one
    error message: <java.lang.NumberFormatException: Invalid int:
    "ffffff94"> when doing poll function

    My simple code is below

    private ArrayBlockingQueue<Byte> iReadQueueArray = new
    ArrayBlockingQueue<Byte>(READBUF_SIZE, true);

    byte[] rbuf = new byte[256];

    iReadCnt = readfromHW(rbuf, rbuf.length); <---read data from
    HW
    ret = iReadQueueArray.offer( Byte.valueOf( (rbuf&0xFF) ));

    //-----------------------------------------------------------------------//
    public int read(byte[] buf) {
    Byte mdata;
    ...
    mdata = (Byte)iReadQueueArray.poll(); <---occur error when
    polling some data
    if( mdata!=null ) {
    buf = (byte) (mdata.byteValue()&0xFF);
    }
    ...
    return 0;
    }
    //-----------------------------------------------------------------------//

    How to modify offer data into the queue and poll data from the
    queue?

    Thank you for your help!

    BR,
    Alan
    bluestar, Jan 29, 2013
    #1
    1. Advertising

  2. bluestar

    bluestar Guest

    I change queue to ArrayBlockingQueue<Integer> iReadQueueArray = new
    ArrayBlockingQueue<Integer>(READBUF_SIZE, true);
    But still it has the same issue

    ret = iReadQueueArray.offer(new Integer((int) (rbuf&0xFF)));

    //-----------------------------------------------------------------------//
    public int read(byte[] buf) {
    Integer mdata;
    ...
    mdata = (Integer)iReadQueueArray.poll();
    if( mdata!=null ) {
    buf = (byte) (mdata.intValue()&0xFF);<---occur error when
    casting some data
    }
    ...
    return 0;
    }
    //-----------------------------------------------------------------------//
    bluestar, Jan 29, 2013
    #2
    1. Advertising

  3. bluestar

    Roedy Green Guest

    On Tue, 29 Jan 2013 01:09:06 -0800 (PST), bluestar
    <> wrote, quoted or indirectly quoted someone
    who said :

    >mdata.intValue()&0xFF);<---occur error when


    You want to see what mdata is. use .getClass()

    from there drill down to find the data.

    As far as I know, NumberFormatExceptions only happen when you convert
    from String to binary.
    I can't see why or where you would be doing that.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    The first 90% of the code accounts for the first 90% of the development time.
    The remaining 10% of the code accounts for the other 90% of the development
    time.
    ~ Tom Cargill Ninety-ninety Law
    Roedy Green, Jan 29, 2013
    #3
  4. On 01/29/2013 06:15 AM, Roedy Green wrote:
    > On Tue, 29 Jan 2013 01:09:06 -0800 (PST), bluestar
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >
    >> mdata.intValue()&0xFF);<---occur error when

    >
    > You want to see what mdata is. use .getClass()
    >
    > from there drill down to find the data.
    >
    > As far as I know, NumberFormatExceptions only happen when you convert
    > from String to binary.
    > I can't see why or where you would be doing that.
    >

    Number objects are more binary than String objects? Who knew?

    An NFE is simply if the String format expected by a conversion to a
    numeric type is not correct.

    As for where it's happening, it's in the error message. I'd want to see
    more of the program myself.

    AHS
    Arved Sandstrom, Jan 29, 2013
    #4
  5. bluestar

    Roedy Green Guest

    On Tue, 29 Jan 2013 06:38:18 -0400, Arved Sandstrom
    <> wrote, quoted or indirectly quoted someone
    who said :

    >Number objects are more binary than String objects? Who knew?


    "123" is a string of characters. 3 x 16-bit unicodes. int i=123 is
    stored internally as 32-bit binary at run-time as is new Integer( 123
    ) in a protective object wrapper.

    Perhaps it is my age, but it is a long standing tradition to refer
    call the process as "converting character/a/alpha/ascii to binary".

    Number is a general term that includes byte, int, float, double,
    packed decimal, fixed length char numerics. (Think COBOL PL/I). In
    Java, Number is an abstract class with ten implementations.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    The first 90% of the code accounts for the first 90% of the development time.
    The remaining 10% of the code accounts for the other 90% of the development
    time.
    ~ Tom Cargill Ninety-ninety Law
    Roedy Green, Jan 30, 2013
    #5
  6. bluestar

    Lew Guest

    Roedy Green wrote:
    > Arved Sandstrom wrote, quoted or indirectly quoted someone who said :
    >>Number objects are more binary than String objects? Who knew?

    >
    > "123" is a string of characters. 3 x 16-bit unicodes. int i=123 is
    > stored internally as 32-bit binary at run-time as is new Integer( 123
    > ) in a protective object wrapper.


    And every real programmer knows that both are binary representations at their heart.

    That's all he's saying.

    > Perhaps it is my age, but it is a long standing tradition to refer
    > call the process as "converting character/a/alpha/ascii to binary".


    A loose description. Arved's was precise.

    > Number is a general term that includes byte, int, float, double,
    > packed decimal, fixed length char numerics. (Think COBOL PL/I). In
    > Java, Number is an abstract class with ten implementations.


    Ten implementations that you know of. There might be more.

    --
    Lew
    Lew, Jan 30, 2013
    #6
  7. bluestar

    Roedy Green Guest

    On Wed, 30 Jan 2013 08:35:11 -0800 (PST), Lew <>
    wrote, quoted or indirectly quoted someone who said :

    >A loose description. Arved's was precise


    He was just playing lawyerly putdown games.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    The first 90% of the code accounts for the first 90% of the development time.
    The remaining 10% of the code accounts for the other 90% of the development
    time.
    ~ Tom Cargill Ninety-ninety Law
    Roedy Green, Jan 31, 2013
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Brown
    Replies:
    0
    Views:
    974
    Bob Brown
    Jul 1, 2003
  2. June Moore
    Replies:
    3
    Views:
    28,748
    Arild Skaar
    Feb 25, 2004
  3. Replies:
    3
    Views:
    1,432
  4. morc

    NumberFormatException

    morc, Mar 2, 2006, in forum: Java
    Replies:
    11
    Views:
    821
    JPractitioner
    Mar 3, 2006
  5. gbattine
    Replies:
    4
    Views:
    3,171
    Rhino
    May 23, 2006
Loading...

Share This Page