3

Here's the code:

        public Object getItem(int position) {
            int top, bot, left, right;

            top = rgnH * position; // line 1
            bot = top + rgnH - (position == getCount() - 1 ? 4 : 0); // line 2
            left = rgnNbr * rgnW + (rgnNbr != 0 ? BORDER : 0); // line 3
            right = (rgnNbr + 1) * rgnW + (rgnNbr == 0 || rgnNbr == maxRgn ? BORDER : 0); // line 4
            rect = new Rect(left, top, right, bot);

            Bitmap bitmap = bitmapDecoder.decodeRegion(rect, op);

            if (inBitmap == null) {
                inBitmap = bitmap;
                op.inBitmap = inBitmap;
            }

            return Bitmap.createScaledBitmap(bitmap, finalW, finalH, true);
        }

Now, my problem is that after line 2 is executed, the app skips directly to the return line. I even tried to delete line 2 so that the code executes line 3 instead, but then again, it jumps ahead to the return line after executing line 3! Please help. Thank you.

Sid Go
  • 2,041
  • 3
  • 16
  • 29
  • 1
    Are you sure it is skipping that line? Like you inserted a printStatement after line 2 and 3 and 4 to make sure its going there? Also just to make it more readable maybe put parentheses around that one line if statement. – 3kings Feb 25 '16 at 00:48
  • I am very sure. I double checked the code many times and even cleaned, rebuilt, restarted android studio. That is why I am posting it here because I am very frustrated right now! BTW: the code posted here is exactly the code I am working on. No more no less. – Sid Go Feb 25 '16 at 00:53
  • I'm assuming the `getCount()` method is just returning a number and not doing anything super crazy – 3kings Feb 25 '16 at 00:55
  • 1
    Did you check if you put a break point by mistake? If you do, look at the line numbers, you should see a red circle. – hehe Feb 25 '16 at 00:56
  • Yea. It returns a constant number. No. Nothing. I told you, I even restarted android studio. I even cleaned the recycle bin if that matters. – Sid Go Feb 25 '16 at 00:56
  • 2
    Are you single stepping in the debugger while observing this behavior or are the values that should be computed incorrect? Optimized code, for example, may not behave as you would like in the debugger. Did you put these print statements in between each line to see what was happening and to check values? – dash-tom-bang Feb 25 '16 at 00:56
  • 2
    This seems to be a bug. I better restructure or change my method name or whatever. I will lose my hair solving this one. – Sid Go Feb 25 '16 at 01:04
  • @SidGo you solved it?. i am facing a similar bug since last update!!! – Kareem Elsayed Apr 10 '17 at 11:12
  • @KareemElsayed I can't remember exactly how I got over this but I know though that this is an IDE bug so a couple of tweaking, cleaning, and a restart will do the job. – Sid Go Apr 10 '17 at 14:31
  • @SidGo i just solved it by recreating the same class again!! thanks. – Kareem Elsayed Apr 10 '17 at 19:52
  • I'm on Android Studio 3.0 Build #AI-171.4408382, and still get this issue a few times a day. Very annoying – Manish Patel Mar 03 '18 at 18:57
  • @SidGo see this: https://stackoverflow.com/questions/21805868/android-studio-debugger-highlights-the-wrong-lines – r.zarei Jun 22 '21 at 11:52

0 Answers0