Strings- String Compression Java

My Code is not passing second test case.
What is wrong with my code?
Please Help.

Input:
aabbaa

Your output:
a4b2

Correct output:
a2b2a2