![]() |
How to remove this issue about NumberFormatException?
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[i]&0xFF) )); //-----------------------------------------------------------------------// public int read(byte[] buf) { Byte mdata; ... mdata = (Byte)iReadQueueArray.poll(); <---occur error when polling some data if( mdata!=null ) { buf[i] = (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 |
Re: How to remove this issue about NumberFormatException?
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[i]&0xFF))); //-----------------------------------------------------------------------// public int read(byte[] buf) { Integer mdata; ... mdata = (Integer)iReadQueueArray.poll(); if( mdata!=null ) { buf[i] = (byte) (mdata.intValue()&0xFF);<---occur error when casting some data } ... return 0; } //-----------------------------------------------------------------------// |
Re: How to remove this issue about NumberFormatException?
On Tue, 29 Jan 2013 01:09:06 -0800 (PST), bluestar
<bluestar8783@gmail.com> 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 |
Re: How to remove this issue about NumberFormatException?
On 01/29/2013 06:15 AM, Roedy Green wrote:
> On Tue, 29 Jan 2013 01:09:06 -0800 (PST), bluestar > <bluestar8783@gmail.com> 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 |
Re: How to remove this issue about NumberFormatException?
On Tue, 29 Jan 2013 06:38:18 -0400, Arved Sandstrom
<asandstrom2@eastlink.ca> 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 |
Re: How to remove this issue about NumberFormatException?
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 |
Re: How to remove this issue about NumberFormatException?
On Wed, 30 Jan 2013 08:35:11 -0800 (PST), Lew <lewbloch@gmail.com>
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 |
| All times are GMT. The time now is 06:19 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.