Error while capturing a view as an Image in android
<p>I have a big problem that I am capturing a view into a Bitmap image but the view is unable to be accessed. Means We unable to get its height or width. Please suggest me where is the problem?</p>

<p><strong>Layout:</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="match_parent" android:background="#ffffff"&gt;
    &lt;FrameLayout android:id="@+id/frameLayout1"
        android:layout_width="fill_parent" android:layout_height="40dip"
        android:background="@color/Red"&gt;
        &lt;TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/tv_Previrew_Header"
            android:text="Greeting" android:textColor="#ffffff"
            android:textStyle="bold" android:textSize="18dip"
            android:layout_gravity="center_vertical|center_horizontal"&gt;&lt;/TextView&gt;
    &lt;/FrameLayout&gt;
    &lt;FrameLayout android:id="@+id/fr"
        android:layout_height="fill_parent" android:layout_width="fill_parent"&gt;
        &lt;Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/btn_email"
            android:background="@drawable/email2x" android:layout_gravity="bottom"&gt;&lt;/Button&gt;
        &lt;ImageView android:id="@+id/img_Preview_Image"
            android:layout_gravity="center_vertical|center_horizontal"
            android:layout_height="270dip" android:layout_width="250dip"&gt;&lt;/ImageView&gt;
        &lt;TextView android:text="TextView" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/tv_Preview_Greeting"
            android:layout_gravity="top|left" android:textColor="@color/Red" android:textSize="20dip" android:textStyle="bold" android:layout_marginLeft="35dip" android:layout_marginTop="40dip"&gt;&lt;/TextView&gt;
        &lt;ImageView android:layout_width="wrap_content" android:src="@drawable/halosys_logo_bottom" android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_gravity="right" android:layout_marginTop="320dip" android:layout_marginRight="40dip"&gt;&lt;/ImageView&gt;
    &lt;/FrameLayout&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p><strong>Code:</strong></p>

<pre><code>FrameLayout view = (FrameLayout)findViewById(R.id.fr);
 Bitmap bm = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
          bm.compress(CompressFormat.JPEG, 95, new FileOutputStream("/sdcard/image.jpg"));
</code></pre>

<p><strong>Error Stack:</strong></p>

<pre><code>12-28 17:16:17.955: ERROR/AndroidRuntime(25935): FATAL EXCEPTION: main
12-28 17:16:17.955: ERROR/AndroidRuntime(25935): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.greetingApp.common/com.greetingApp.common.Greeting}: java.lang.IllegalArgumentException: width and height must be &gt; 0
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.os.Looper.loop(Looper.java:123)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at java.lang.reflect.Method.invokeNative(Native Method)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at java.lang.reflect.Method.invoke(Method.java:521)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at dalvik.system.NativeStart.main(Native Method)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935): Caused by: java.lang.IllegalArgumentException: width and height must be &gt; 0
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.graphics.Bitmap.nativeCreate(Native Method)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at com.greetingApp.common.Greeting.SaveData(Greeting.java:109)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at com.greetingApp.common.Greeting.onCreate(Greeting.java:81)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-28 17:16:17.955: ERROR/AndroidRuntime(25935):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
</code></pre>
