Program force close when debugging or running
<p>Previously my program was working well on different sizes of screen and devices. After I added some buttons to x-large screen and edited the layout to be different for all screen sizes the device prompts me to force close the program when I run it on all layout besides x-large. What is the problem??</p>

<pre><code>    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  //**********************1 inch is about 160dp*********************
     setContentView(R.layout.main);

     Display display = getWindowManager().getDefaultDisplay();

     int width = display.getWidth();  
     //int height = display.getHeight();  

     //for different sizes of screens, set range of position of scrollbars
     if(width &gt; 1200)
     {
         maxY = 325;
         minY = 275;
         maxX = 700;
         minX = 600;
         limitY = 210;
         limitY2 = 360;
         axisSelector = 1; //use x
     }

     else
     {
         //to be edited
         axisSelector = 0;
         maxY = 250;
         minY = 200;
         maxX = 500;
         minX = 400;
         limitY = 120;
         limitY2 = 270;

     }

    mainLayout = (LinearLayout) findViewById(R.id.controlLayout);
    mainLayout.setOnTouchListener(this);

    localBtDevice = (TextView) findViewById(R.id.txtLocalBtDevice);
    remoteBtDevices = (ListView) findViewById(R.id.lstRemoteBtDevices);
    btStatus = (TextView) findViewById(R.id.txtBtStatus);
    txtCalibrate = (TextView) findViewById(R.id.txtCalibrate);
    txtCalibrate.setText(String.valueOf(calValue));
    btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter == null) {
        btStatus.setText(" &gt; Bluetooth not available!");
        return;
    }
    localBtDevice.setText("  " + btAdapter.getName());
    Set&lt;BluetoothDevice&gt; devices = btAdapter.getBondedDevices();
    Iterator&lt;BluetoothDevice&gt; device = devices.iterator();
    final String[] deviceList = new String[devices.size()];
    final String[] addressList = new String[devices.size()];
    for (int i = 0; i &lt; devices.size(); i++) {
        BluetoothDevice dev = device.next();
        deviceList[i] = dev.getName();
        addressList[i] = dev.getAddress();
    }
    remoteBtDevices.setAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, deviceList));
    deviceSelected = "";
    remoteBtDevices.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View view, int pos, long id) {
            btStatus.setText(" &gt; Connect to \"" + deviceList[pos] + "\"?");
            deviceSelected = deviceList[pos];
            addressSelected = addressList[pos];
            return false;
        }
    });

    btnBtAccess = (Button) findViewById(R.id.btnBtAccess);
    if (BtConnected == false) {
        btStatus.setText(" &gt; Disconnected.");
        btnBtAccess.setText("Connect");
    }
    else {
        btStatus.append(" &gt; You are connected to \"" + socketEP.getRemoteDevice().getName()+ "\".");
        btnBtAccess.setText("Close");
    }
    btnBtAccess.setOnClickListener(ConnectRobotListener);

    btnCalLeft = (Button) findViewById(R.id.btnCalLeft);
    btnCalLeft.setOnClickListener(CalLeftListener);
    btnCalRight = (Button) findViewById(R.id.btnCalRight);
    btnCalRight.setOnClickListener(CalRightListener);

    progressBarX = (ProgressBar) findViewById(R.id.ProgressBarHorz);
    progressBarX.setMax(200);
    progressBarX.setProgress(100);
    steeringText = (TextView)findViewById(R.id.txtSteering);

    progressBarY = (VerticalProgressBar) findViewById(R.id.ProgressBarVert);
    progressBarY.setMax(200);
    progressBarY.setProgress(100);
    throtleText = (TextView) findViewById(R.id.txtThrotle);

  //***********************************************************************************************  
    button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (btnBtAccess.getText() == "Close") {     
            button1count++;
            if(button1count % 2 == 0){
            button1.setText("Tilt Steer Enabled");
            selector++;
        }
            else{
            button1.setText("Tilt Steer Disabled");
            selector++;
            }
        }
        }
    });
  //************************************************************************************************** 
    button3 = (Button) findViewById(R.id.button3);
    button3.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (btnBtAccess.getText() == "Close") {     
            steerCountLeft++;
            if(steerCountLeft % 2 == 1)
            steer--;
            if(steer &lt; 0)
               steer = 0;
            if(steer &lt; 30)
            {
                try {
                    int calDirection = (int)((30 - steer) - calValue);                          
                    if (calDirection &lt; 0)
                        calDirection = 0;
                    RoboController.outputStream.write('L');
                    RoboController.outputStream.write(calDirection);
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    steeringText.setText("L "+String.valueOf((int)(30 - steer)+" deg"));    
                    int steer1 = ( ((steer * 334) / 100));
                    progressBarX.setProgress(steer1);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }

            }
            else
            {
                try {
                    int calDirection = (int)((steer - 30) - calValue);                          
                    if (calDirection &lt; 0)
                        calDirection = 0;
                    RoboController.outputStream.write('R');
                    RoboController.outputStream.write(calDirection);
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    steeringText.setText("R "+String.valueOf((int)(steer - 30)+" deg"));    
                    int steer1 = ( ((steer * 334) / 100));
                    progressBarX.setProgress(steer1);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }

            }
            }
            return true;
        }
    });
  //**************************************************************************************************  
    button2 = (Button) findViewById(R.id.button2);
    button2.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (btnBtAccess.getText() == "Close") {     
            steerCountRight++;
            if(steerCountRight % 2 == 1)
            steer++;
            if(steer &gt; 60)
               steer = 60;
            if(steer &gt; 30)
            {
                try {
                    int calDirection = (int)((steer - 30) - calValue);                          
                    if (calDirection &lt; 0)
                        calDirection = 0;
                    RoboController.outputStream.write('R');
                    RoboController.outputStream.write(calDirection);
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    steeringText.setText("R "+String.valueOf((int)(steer - 30)+" deg"));    
                    steer1 = ( ((steer * 334) / 100));
                    progressBarX.setProgress(steer1);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }
            }
            else
            {
                try {
                    int calDirection = (int)((30 - steer) - calValue);                          
                    if (calDirection &lt; 0)
                        calDirection = 0;
                    RoboController.outputStream.write('L');
                    RoboController.outputStream.write(calDirection);
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    steeringText.setText("L "+String.valueOf((int)(30 - steer)+" deg"));    
                    steer1 = ( ((steer * 334) / 100));
                    progressBarX.setProgress(steer1);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }
            }
            }
            return true;
        }
    });
    //***************************************************************************
    button4 = (Button) findViewById(R.id.button4);
    button4.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (btnBtAccess.getText() == "Close") {     
                move++;
            if(move &gt; 100)
               move = 100;

            if(move &gt; 0)
            {

                try {
                    RoboController.outputStream.write('F');
                    RoboController.outputStream.write((int)(move));
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    throtleText.setText("F "+String.valueOf((int)(move)+" cm/s"));
                    progressBarY.setProgress(100 + move);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }

            }
            else
            {
                try {
                    RoboController.outputStream.write('B');
                    RoboController.outputStream.write((int)(-move));
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    throtleText.setText("B "+String.valueOf((int)(-move)+" cm/s"));
                    progressBarY.setProgress(100 + move);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }
            }
            }


            return true;
        }
    });


    //**************************************************************************************
    button5 = (Button) findViewById(R.id.button5);
    button5.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (btnBtAccess.getText() == "Close") {     

            move--;
            if(move &lt; -100)
               move = -100;
            if(move &lt; 0)
            {
                try {
                    RoboController.outputStream.write('B');
                    RoboController.outputStream.write((int)(-move));
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    throtleText.setText("B "+String.valueOf((int)(-move)+" cm/s"));
                    progressBarY.setProgress(100+ move);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }
            }
            else
            {
                try {
                    RoboController.outputStream.write('F');
                    RoboController.outputStream.write((int)(move));
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    throtleText.setText("F "+String.valueOf((int)(move)+" cm/s"));
                    progressBarY.setProgress(100 + move);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }
            }
            }
            return true;
        }
    });




    //************************************************************************************
    button6 = (Button) findViewById(R.id.button6);
    button6.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (btnBtAccess.getText() == "Close") {     
                move = 100;
                try {
                    RoboController.outputStream.write('F');
                    RoboController.outputStream.write((int)(move));
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    throtleText.setText("F "+String.valueOf((int)(move)+" cm/s"));
                    progressBarY.setProgress(100 + move);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }

            }

        }
    });


    //**********************************************************************************
    button7 = (Button) findViewById(R.id.button7);
    button7.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (btnBtAccess.getText() == "Close") {     
                move = 0;
                try {
                    RoboController.outputStream.write('F');
                    RoboController.outputStream.write((int)(move));
                    RoboController.outputStream.write('\r');
                    RoboController.outputStream.write('\n');
                    throtleText.setText("F "+String.valueOf((int)(move)+" cm/s"));
                    progressBarY.setProgress(100 + move);
                } catch (IOException e) {
                    btStatus.setText(" &gt; Error sending data!");
                }

            }

        }
    });
    //**********************************************************************************
    button8 = (Button) findViewById(R.id.button8);
    button8.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (btnBtAccess.getText() == "Close") {     
                move = -100;
                try {
                        RoboController.outputStream.write('B');
                        RoboController.outputStream.write((int)(-move));
                        RoboController.outputStream.write('\r');
                        RoboController.outputStream.write('\n');
                        throtleText.setText("B "+String.valueOf((int)(-move)+" cm/s"));
                        progressBarY.setProgress(100+ move);
                    } catch (IOException e) {
                        btStatus.setText(" &gt; Error sending data!");
                    }

            }

        }
    });

    //************************************************************************************
    button9 = (Button) findViewById(R.id.button9);
    button9.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (btnBtAccess.getText() == "Close") {     
                steer = 30;
                try {
                    int calDirection = (int)((steer - 30) - calValue);
                        RoboController.outputStream.write('L');
                        RoboController.outputStream.write(calDirection);
                        RoboController.outputStream.write('\r');
                        RoboController.outputStream.write('\n');
                        steeringText.setText("L "+String.valueOf((int)(steer - 30)+" deg"));
                        steer1 = (steer * 334) / 100;
                        progressBarX.setProgress(steer1);
                    } catch (IOException e) {
                        btStatus.setText(" &gt; Error sending data!");
                    }

            }

        }
    });

    //**********************************************************************************
    // imageTouchPadHorz=( ImageView )findViewById(R.id.imageTouchPadHorz);
    // imageTouchPadHorz.setOnTouchListener(new View.OnTouchListener(){







  //**************************************************************************************************  


    ((SensorManager)getSystemService(Context.SENSOR_SERVICE)).registerListener(
             new SensorEventListener() {    
                @Override  
                public void onSensorChanged(SensorEvent event) {  


                    if(button1.getText() == "Tilt Steer Enabled" &amp;&amp; btnBtAccess.getText() == "Close")
                    {


                        if(axisSelector == 0)
                        {
                            xPos2 = -event.values[0] * 3;
                            xPos2 = ((xPos2 * 100) / 10) / 3; 
                            axis1 = xPos2;
                            yPos2 = -event.values[1];
                            yPos2 = yPos2 * 10; 
                            axis = yPos2;
                        }

                        else
                        {
                            xPos2 = -event.values[0] * 3;
                            xPos2 = ((xPos2 * 100) / 10) / 3; 
                            axis = xPos2;
                            yPos2 = -event.values[1];
                            yPos2 = yPos2 * 10; 
                            axis1 = yPos2;

                        }
                        if(axis &gt; 30)
                            axis = 30;
                        if(axis &lt; -30)
                            axis = -30;
                        if(axis &lt; 0)
                        {
                            try
                            {
                                int calDirection2 = (int)(-axis);
                                RoboController.outputStream.write('L');
                                RoboController.outputStream.write(calDirection2);
                                RoboController.outputStream.write('\r');
                                RoboController.outputStream.write('\n');
                                steeringText.setText("L "+String.valueOf((int)(-axis)+" deg"));
                                int xPos3 = (int)axis;
                                xPos3 = 100 + ((xPos3 * 334) / 100);
                                progressBarX.setProgress(xPos3);

                            }   catch (IOException e) {
                                btStatus.setText(" &gt; Error sending data!");
                            }
                        }

                        else
                        {
                            try
                        {
                            int calDirection2 = (int)(axis);
                            RoboController.outputStream.write('R');
                            RoboController.outputStream.write(calDirection2);
                            RoboController.outputStream.write('\r');
                            RoboController.outputStream.write('\n');
                            steeringText.setText("R "+String.valueOf((int)(axis)+" deg"));
                            int xPos3 = (int)axis;
                            xPos3 = ((xPos3 * 334) / 100) + 100;
                            progressBarX.setProgress(xPos3);
                        }   catch (IOException e) {
                            btStatus.setText(" &gt; Error sending data!");
                        }

                        }

                        if(axis1 &gt; 50)
                            axis1 = 50;
                        if(axis1 &lt; -50)
                            axis1 = -50;
                        if(axis1 &gt; 0)
                        {
                            try {
                                RoboController.outputStream.write('F');
                                RoboController.outputStream.write((int)(axis1 * 2));
                                RoboController.outputStream.write('\r');
                                RoboController.outputStream.write('\n');
                                //throtleText.setText("F " + String.valueOf((int)(100-(axis1 * 2))) + " cm/s");
                                throtleText.setText("F " + String.valueOf((int)(axis1 * 2)) + " cm/s");
                                int yPos3 = (int)axis1;
                                yPos3 = yPos3 * 2;
                                progressBarY.setProgress(100+yPos3);
                            } catch (IOException e) {
                                btStatus.setText(" &gt; Error sending data!");
                            }
                        }

                        if(axis1 &lt; 0)
                        {
                            try {
                                RoboController.outputStream.write('B');
                                RoboController.outputStream.write((int)(-axis1 * 2));
                                RoboController.outputStream.write('\r');
                                RoboController.outputStream.write('\n');
                                throtleText.setText("B " + String.valueOf((int)(-axis1 * 2)) + " cm/s");
                                int yPos3 = (int)axis1;
                                yPos3 = yPos3 * 2;
                                progressBarY.setProgress(100+yPos3);
                            } catch (IOException e) {
                                btStatus.setText(" &gt; Error sending data!");
                            }
                        }

               }
               }
                @Override  
                public void onAccuracyChanged(Sensor sensor, int accuracy) {} //ignore
            },
            ((SensorManager)getSystemService(Context.SENSOR_SERVICE))
            .getSensorList(Sensor.TYPE_ACCELEROMETER).get(0),   
             SensorManager.SENSOR_DELAY_NORMAL);


    //*************************************************************************************************************************
}



@Override
public boolean onTouch(View v, MotionEvent event) {
    int xPos, yPos, action, actionCode;

    if (btnBtAccess.getText() == "Close") {         
        xPos = 0;
        yPos = 0; 
        for (int i = 0; i &lt; event.getPointerCount(); i++) {
            xPos = (int)event.getX(i);
            yPos = (int)event.getY(i);


            if (xPos &lt; 200) { 
                //switch(v.getId()){
                //case R.id.imageTouchPadHorz://original code(   
            //if (xPos &gt; 0 ) {                                          //testing purpose not needed
                if (yPos &gt; minY &amp;&amp; yPos &lt; maxY) {                           //original code (edited) 275 - 325
                //if(yPos &gt;0 ){                                         //testing purpose not needed
                    //xPos -= 5;                                        //whats the purpose
                    if (xPos &gt; 150)                                     //original is 200
                        xPos = 150;                                     //original is 200
                    else if (xPos &lt; 2)
                        xPos = 0;

                    if (xPos &lt; 75) {    
                        if(selector % 2 == 1){
                        //original is 100
                        //int calDirection..... is to calculate value for pcb
                        //RoboController.outputStream.write is to write value on LCD
                        //steering text is to display on android device
                        //progressBarX is to fill the bar with yellow colour
                        try {
                            int calDirection = (int)((75-xPos)/2.4 - calValue);                         //100 , 3.3
                            if (calDirection &lt; 0)
                                calDirection = 0;
                            RoboController.outputStream.write('L');
                            RoboController.outputStream.write(calDirection);
                            RoboController.outputStream.write('\r');
                            RoboController.outputStream.write('\n');
                            steeringText.setText("L "+String.valueOf((int)((75-xPos)/2.4))+" deg");     //100 , 3.3
                            //extra calculation to completely fill the bar
                            //due to the change of value from 200 -&gt; 150, 100 -&gt; 75
                            //used *133/100 as xPos and progressbar is int
                            //1.33 as 75*1.33 and 150*1.33 is almost = 100, 200
                            xPos = (xPos*133)/100;                      
                            progressBarX.setProgress(xPos);
                        } catch (IOException e) {
                            btStatus.setText(" &gt; Error sending data!");
                        }
                    }
                    }
                    else {
                        if(selector % 2 == 1){
                        //all changes are same as above
                        try {
                            int calDirection = (int)((xPos-75)/2.42 + calValue);            
                            if (calDirection &lt; 0)
                                calDirection = 0;
                            RoboController.outputStream.write('R');
                            RoboController.outputStream.write(calDirection);
                            RoboController.outputStream.write('\r');
                            RoboController.outputStream.write('\n');
                            steeringText.setText("R "+String.valueOf((int)((xPos-75)/2.42))+" deg");
                             xPos = (xPos * 133) / 100;
                            progressBarX.setProgress(xPos);
                        } catch (IOException e) {
                            btStatus.setText(" &gt; Error sending data!");
                        }
                    }
                    }
                }
            }
    //      }


                    //values are calculated and changed to suit the UI of my device.
                    //original difference between the max value of height and min value was 200
                    // mine is 
            //******************************************************************************************
            else if (xPos &gt; minX &amp;&amp; xPos &lt; maxX) {    //orignal is x &gt; 900    set the limit length of scroll 600-700
                    //i used 220 - &gt; 350, but the increase in limit is for clearance 
                if (yPos &gt; limitY &amp;&amp; yPos &lt; limitY2) {                  //original is y &gt; 100   set the limit height of scroll
                    action = event.getAction();
                    actionCode = action &amp; MotionEvent.ACTION_MASK;
                    if (actionCode == MotionEvent.ACTION_POINTER_UP || actionCode == MotionEvent.ACTION_UP)
                    {
                        yPos = 285;                 //285 is the center of scrollbar    //original is 420
                        //yPos = yPos - 185;
                    }
                    else
                    {
                        if (yPos &gt; 350)             //original is y &gt; 520
                        {
                            yPos = 350;             //min value of scroll bar
                            //yPos = yPos - 150;
                        }
                        else if (yPos &lt; 220)        //original is y &lt; 320
                        {
                            yPos = 220;             //max value of scroll bar
                            //yPos = 220 - 220;
                        }
                    }
                    //purpose of 1.5405 is when scrollbar value is 285, difference of 285*1.5405 - 339 must be at least
                    //or equals to 100 yet it cannot be too big. 99.9 or 100.1 will affect the max and min value of cm/s
                    //the maximum difference is made as 200 so as to make life easier when calculating and displaying
                    //the value on screen and the progressbar. 
                    //best to use simple multiplication factors of 200
                    yPos = ((yPos * 15405)/10000) - 339;     
                    if (yPos &lt; 100) {
                        if(yPos &lt; 1)            //this if is used to prevent forward 101 from coming out
                            yPos = 0;
                        try {
                            RoboController.outputStream.write('F');
                            RoboController.outputStream.write((int)(100-yPos));
                            RoboController.outputStream.write('\r');
                            RoboController.outputStream.write('\n');
                            throtleText.setText("F " + String.valueOf((int)(100-yPos)) + " cm/s");
                            progressBarY.setProgress(200-yPos);
                        } catch (IOException e) {
                            btStatus.setText(" &gt; Error sending data!");
                        }
                    }
                    else {
                        try {
                            RoboController.outputStream.write('B');
                            RoboController.outputStream.write((int)(yPos-100));
                            RoboController.outputStream.write('\r');
                            RoboController.outputStream.write('\n');
                            throtleText.setText("B " + String.valueOf((int)(yPos-100)) + " cm/s");
                            progressBarY.setProgress(200-yPos);
                        } catch (IOException e) {
                            btStatus.setText(" &gt; Error sending data!");
                        }
                    }
                }
            }
        }

    }

    return true;
}


//**********************************************************************************************************![xlarge image][1]
</code></pre>

<p><img src="http://i.stack.imgur.com/ATUQb.jpg" alt="xlarge image"></p>

<p><img src="http://i.stack.imgur.com/RUidA.jpg" alt="normal"></p>

<p><img src="http://i.stack.imgur.com/1zHD2.jpg" alt="enter image description here"></p>
