Rotating image on button click
<p>I had created a small app such that the image which is displaying should rotate when I click the button. I have written the following code:</p>

<pre><code>import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;


public class ImageActivity extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }  
    public void Rotate()
    {

        ImageView img = (ImageView)findViewById(R.id.imageView01);
        Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.bharath);
// Getting width &amp; height of the given image.
        int w = bmp.getWidth();
        int h = bmp.getHeight();
// Setting pre rotate to 90
        Matrix mtx = new Matrix();
        mtx.preRotate(90);
// Rotating Bitmap
        Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
        BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
        img.setImageDrawable(bmd);
    }
</code></pre>

<p>Now when I execute the code and click the button to rotate the image, the application is forcing me to close it, mentioning there is an unexpected error. I could not trace and correct. Can any one please help me in this regard?</p>
