0

I'm working with Android, and I've one of the weirdest error ever. This function checks wether I can or not set a bigger Font for a Paint object.

What I´m seeing here, is that EVEN when the first if sentence is TRUE... and the next one is also true, after returning the value "true"... it jumps to the last "return false;" which is absolutely imposible!

Do any of you have any idea why this could be happening? Thanks !!!

private boolean fontCanBeBigger(String text, Paint paint, Canvas canvas, int divisor){      
    if (textFitsOneLine(text, paint, canvas))
    {           
        paint.setTextSize(divisor-2);           
        if (textFitsOneLine(text, paint, canvas) && (divisor > MIN_DIVISOR))                                
        {
                paint.setTextSize(divisor+2); 
                return true;
        }
        else
        {
            paint.setTextSize(divisor+2); //set it back to previous value
            return false;
        }           
    }
    else { return false; }  
}

private boolean textFitsOneLine(String text, Paint paint, Canvas canvas)
{
    int length = paint.breakText(text, true,(float) canvas.getWidth()- MARGIN, null);       
    return length >= text.length();
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • `Do any of you have any idea why this could be happening?` Not without seeing the code for `textFitsOneLine()` – Phantômaxx May 11 '14 at 12:52
  • here you have : `private boolean textFitsOneLine(String text, Paint paint, Canvas canvas){ int length=paint.breakText(text, true,(float) canvas.getWidth()- MARGIN, null); return length >= text.length(); }` – user3625489 May 11 '14 at 12:56
  • How do you think you're observing that it returned `true` and then `false`? What I think is more likely is that maybe you called 1\`fontCanBeBigger` twice, and it return true then false. (maybe it returned true once, paint was made bigger, and then so next time `textFitsOneLine` was false) – aamit915 May 11 '14 at 13:00
  • possible duplicate of [Android Studio debugger highlights the wrong lines](http://stackoverflow.com/questions/21805868/android-studio-debugger-highlights-the-wrong-lines) –  May 11 '14 at 13:00
  • When launching the app, I see that the result is false... so I debug the app, and when debugging I see that it goes inside the if statement, goes to the next one, returns true, and then it goes straight to the return false, and that´s what I get. – user3625489 May 11 '14 at 13:04
  • Correction: I've put some traces to track if it was a Debug funny problem, and you're right, debugger is highlighting the wrong line. Thanks everone for your help! – user3625489 May 11 '14 at 13:24

1 Answers1

0

It's probably UI glitch of the debugger, but only a single execution path of the if statement is actually executed

elmorabea
  • 3,243
  • 1
  • 14
  • 20