Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21828 > unrolled thread

How to remove this issue about NumberFormatException?

Started bybluestar <bluestar8783@gmail.com>
First post2013-01-29 00:09 -0800
Last post2013-01-31 04:21 -0800
Articles 7 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  How to remove this issue about NumberFormatException? bluestar <bluestar8783@gmail.com> - 2013-01-29 00:09 -0800
    Re: How to remove this issue about NumberFormatException? bluestar <bluestar8783@gmail.com> - 2013-01-29 01:09 -0800
      Re: How to remove this issue about NumberFormatException? Roedy Green <see_website@mindprod.com.invalid> - 2013-01-29 02:15 -0800
        Re: How to remove this issue about NumberFormatException? Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-29 06:38 -0400
          Re: How to remove this issue about NumberFormatException? Roedy Green <see_website@mindprod.com.invalid> - 2013-01-30 04:55 -0800
            Re: How to remove this issue about NumberFormatException? Lew <lewbloch@gmail.com> - 2013-01-30 08:35 -0800
              Re: How to remove this issue about NumberFormatException? Roedy Green <see_website@mindprod.com.invalid> - 2013-01-31 04:21 -0800

#21828 — How to remove this issue about NumberFormatException?

Frombluestar <bluestar8783@gmail.com>
Date2013-01-29 00:09 -0800
SubjectHow to remove this issue about NumberFormatException?
Message-ID<5d71bb47-c763-403a-8405-89708b399442@sb6g2000pbb.googlegroups.com>
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

[toc] | [next] | [standalone]


#21829

Frombluestar <bluestar8783@gmail.com>
Date2013-01-29 01:09 -0800
Message-ID<50fa3023-1503-4c5b-853f-ff529b26734b@d8g2000pbm.googlegroups.com>
In reply to#21828
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;
    }
//-----------------------------------------------------------------------//

[toc] | [prev] | [next] | [standalone]


#21831

FromRoedy Green <see_website@mindprod.com.invalid>
Date2013-01-29 02:15 -0800
Message-ID<f38fg85vnq3cjno9jbu25mq0n0p3vh2bbi@4ax.com>
In reply to#21829
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 

[toc] | [prev] | [next] | [standalone]


#21834

FromArved Sandstrom <asandstrom2@eastlink.ca>
Date2013-01-29 06:38 -0400
Message-ID<vENNs.28482$O02.26239@newsfe18.iad>
In reply to#21831
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

[toc] | [prev] | [next] | [standalone]


#21867

FromRoedy Green <see_website@mindprod.com.invalid>
Date2013-01-30 04:55 -0800
Message-ID<7t4ig81a1brc4up6t6huk894lp23c51oic@4ax.com>
In reply to#21834
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 

[toc] | [prev] | [next] | [standalone]


#21873

FromLew <lewbloch@gmail.com>
Date2013-01-30 08:35 -0800
Message-ID<03b6cd9b-9764-48fb-9c87-2ddfd7bba0ee@googlegroups.com>
In reply to#21867
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

[toc] | [prev] | [next] | [standalone]


#21921

FromRoedy Green <see_website@mindprod.com.invalid>
Date2013-01-31 04:21 -0800
Message-ID<4eokg8h9an3pgln77hkqcefm0cp3n618cl@4ax.com>
In reply to#21873
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 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web