Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: StringBuilder.append( double ) throws ArrayIndexOutOfBoundsException

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default StringBuilder.append( double ) throws ArrayIndexOutOfBoundsException

    Hi,

    I got an exception report from a client. In this report StringBuilder.append( double ) throws an ArrayIndexOutOfBoundsException.

    There is no thread issue involved, because that code simply looks as follows:
      StringBuilder sb = new StringBuilder( "" );		
      sb.append( degrees ); // This is the line that throws an exception (degrees is of type double)
    The stack trace of the exception is:
    	at java.lang.RealToString.longDigitGenerator(RealToString.java:274)
    	at java.lang.RealToString.convertDouble(RealToString.java:111)
    	at java.lang.RealToString.appendDouble(RealToString.java:63)
    	at java.lang.StringBuilder.append(StringBuilder.java:185)
    	at my code
    The code runs on an Android telephone LG-C660h.
    Android version: 2.3.4
    Android API: 10

    Any ideas?

    Thanks in advance.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: StringBuilder.append( double ) throws ArrayIndexOutOfBoundsException

    Any idea what the value of degrees is when this exception is thrown? Could it be one of double's edge values: Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY?

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: StringBuilder.append( double ) throws ArrayIndexOutOfBoundsException

    I don't know, but I don't think this is very likely. I got this from an automatic report sent from a client device, so I don't have the value.

    Following your question, I tried the code below on my Samsung S II, and it produced no exception:

    		StringBuilder sb1 = new StringBuilder( "" );
    		sb1.append( Double.MAX_VALUE );
     
    		StringBuilder sb2 = new StringBuilder( "" );
    		sb2.append( Double.MIN_VALUE );
     
    		StringBuilder sb3 = new StringBuilder( "" );
    		sb3.append( Double.NaN );
     
    		StringBuilder sb4 = new StringBuilder( "" );
    		sb4.append( Double.NEGATIVE_INFINITY );
     
    		StringBuilder sb5 = new StringBuilder( "" );
    		sb5.append( Double.POSITIVE_INFINITY );

Similar Threads

  1. StringBuilder
    By Anoop Shiralige in forum Java Theory & Questions
    Replies: 1
    Last Post: June 23rd, 2012, 08:08 AM
  2. [SOLVED] New line and StringBuilder
    By newbie in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 1st, 2011, 09:42 PM
  3. Replies: 2
    Last Post: February 25th, 2010, 04:17 PM
  4. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java SE API Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 10:42 AM
  5. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 10:42 AM