I want to make sure that the fields are not empty before the submit button is pressed to stop the application from crashing.

this is my code

```js
package com.alrabei.edcalactivity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class edcalactivity extends AppCompatActivity {

    EditText firstNumber;
    EditText secondNumber;
    EditText thirdnum;
    EditText forthnum;
    TextView showresult;
    Button buadd1;

    double num1,num2,num3,num4,sum1,sum2,sum3,TotalBuy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edcal_activity);

        firstNumber = (EditText)findViewById(R.id.s1);
        secondNumber = (EditText)findViewById(R.id.p1);
        thirdnum = (EditText)findViewById(R.id.s2);
        forthnum = (EditText)findViewById(R.id.p2);
        showresult = (TextView)findViewById(R.id.result);
        buadd1 = (Button)findViewById(R.id.bu1);

        buadd1.setOnClickListener(new View.OnClickListener() {

          public void onClick(View v) {

              num1 = Double.parseDouble(firstNumber.getText().toString());
              num2 = Double.parseDouble(secondNumber.getText().toString());
              num3 = Double.parseDouble(thirdnum.getText().toString());
              num4 = Double.parseDouble(forthnum.getText().toString());

              if((firstNumber.getText().length()>0) && (secondNumber.getText().length()>0) && (thirdnum.getText().length()>0) && (forthnum.getText().length()>0))
              {
                  sum1 = num1 + num3;
                  TotalBuy = (num1 * num2) + (num3 * num4);
                  // sum2 = num2 + num4;
                  // sum3 = sum2 / sum1;
                  sum3 = TotalBuy / sum1;

                  showresult.setText(Double.toString(sum3));
              }
              else{
                  showresult.setText("Error");
              }

           }

        });

    }

}
```

and this is the xml file

```html
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context="com.alrabei.edcalactivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView5"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="العدد السابق" />

        <EditText
            android:id="@+id/s1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:ems="10"
            android:inputType="number" />

        <TextView
            android:id="@+id/textView9"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="السعر:" />

        <EditText
            android:id="@+id/p1"
            android:layout_width="171dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number|numberDecimal" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="الجديد" />

        <EditText
            android:id="@+id/s2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number" />

        <TextView
            android:id="@+id/textView10"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="القيمة:" />

        <EditText
            android:id="@+id/p2"
            android:layout_width="173dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number|numberDecimal" />

    </LinearLayout>

    <Button
        android:id="@+id/bu1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:maxLength="5"
        />

</LinearLayout>
```

i did an if statement to make sure that the user will enter a number in the edittext but it doesn't work .. can you help me what is wrong with the code..