Q:

App is FC if the user presses too much to left or right

I have the following XML:
<LinearLayout
    android:id="@+id/llColorSpect"
    android:layout_width="match_parent"
    android:layout_height="@dimen/color_scheme_height"
    android:orientation="vertical"
    android:background="@drawable/colorspect"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginBottom="@dimen/seek_bar_margin"
    android:layout_below="@+id/tvBGColor" >
    <RelativeLayout
        android:id="@+id/rlColorSpect"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <ImageView
            android:id="@+id/ivSquare"
            android:layout_width="@dimen/title_text_pad"
            android:layout_height="@dimen/title_text_pad"
            android:layout_alignParentBottom="true"
            android:scaleType="fitXY"
            android:src="@drawable/esquare" />
    </RelativeLayout>
</LinearLayout>

My partial Java code:
View. OnTouchListener llTouch = new View. OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int x = (int)event.getX();
        int y = (int)event.getY();
        int action = event.getAction();
        int pixel = bitmap.getPixel((int)x,(int) y);

        switch (action & MotionEvent. ACTION_MASK) {
            case MotionEvent. ACTION_DOWN: {
                Log.i("COORDINATES","Touch coordinates : x" + String.valueOf(x) + "y" + String.valueOf(y));
                ivTouch.setX(x);
                ivTouch.setY(y);
                int redValue = Color.red(pixel);
                int blueValue = Color.blue(pixel);
                int greenValue = Color.green(pixel);
                Log.d("Colors","R:" +redValue +" G:" +greenValue+" B:" + blueValue);
                sbRed.setProgress(redValue);
                sbGreen.setProgress(greenValue);
                sbBlue.setProgress(blueValue);
                dispHVal();
            break;
            }
            case MotionEvent. ACTION_MOVE:{
                Log.i("COORDINATES","Touch coordinates : x" + String.valueOf(x) + "y" + String.valueOf(y));
                ivTouch.setX(x);
                ivTouch.setY(y);
                int redValue = Color.red(pixel);
                int blueValue = Color.blue(pixel);
                int greenValue = Color.green(pixel);
                Log.d("Colors","R:" +redValue +" G:" +greenValue+" B:" + blueValue);
                sbRed.setProgress(redValue);
                sbGreen.setProgress(greenValue);
                sbBlue.setProgress(blueValue);
                dispHVal();
            break;
            }
        }
        return true;
    }
};

The issue I am coming across. 

While pressing on the layout to get the coordinate on certain part of it (If I press/drag all the way to the left or to the right), my app FC.  I am adding the LogCat below:

01-25 01:13:21.059: E/AndroidRuntime(13345): FATAL EXCEPTION: main
  01-25 01:13:21.059: E/AndroidRuntime(13345):
  java.lang. IllegalArgumentException: x must be < bitmap.width() 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.graphics. Bitmap.checkPixelAccess(Bitmap.java:1155) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.graphics. Bitmap.getPixel(Bitmap.java:1107) 01-25 01:13:21.059:
  E/AndroidRuntime(13345):  at
  com.test.testing. MainActivity$1.onTouch(MainActivity.java:98) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.view. View.dispatchTouchEvent(View.java:7241) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.view. ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewGroup.dispatchTouchEvent(ViewGroup.java:1903) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.view. ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewGroup.dispatchTouchEvent(ViewGroup.java:1875) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.view. ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewGroup.dispatchTouchEvent(ViewGroup.java:1875) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.view. ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewGroup.dispatchTouchEvent(ViewGroup.java:1875) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.view. ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewGroup.dispatchTouchEvent(ViewGroup.java:1875) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  com.android.internal.policy.impl. PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  com.android.internal.policy.impl. PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.app. Activity.dispatchTouchEvent(Activity.java:2410) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  com.android.internal.policy.impl. PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. View.dispatchPointerEvent(View.java:7426) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.view. ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.view. InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  android.os. MessageQueue.nativePollOnce(Native Method) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.os. MessageQueue.next(MessageQueue.java:125) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  android.os. Looper.loop(Looper.java:124) 01-25 01:13:21.059:
  E/AndroidRuntime(13345):  at
  android.app. ActivityThread.main(ActivityThread.java:5195) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  java.lang.reflect. Method.invokeNative(Native Method) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  java.lang.reflect. Method.invoke(Method.java:511) 01-25 01:13:21.059:
  E/AndroidRuntime(13345):  at
  com.android.internal.os. ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
  01-25 01:13:21.059: E/AndroidRuntime(13345):  at
  com.android.internal.os. ZygoteInit.main(ZygoteInit.java:562) 01-25
  01:13:21.059: E/AndroidRuntime(13345):    at
  dalvik.system. NativeStart.main(Native Method)

I want to allow the user to be able to drag all the way to the left, top, right, and bottom.  How do I modify the above code to achieve that?  Thanks!!! 

A:

Move your x and y logging to before you access the bitmap to see what values are being returned. 
Per the stacktrace, don't call getPixel with values x and y which exceed the dimensions of your bitmap.