title: Multiplication between two text fields - Android Java
body: <p>I am new to Android and programming and having a bit of difficulties with my code. I tried to research this but couldn't find out what was wrong, would appreciate the help. I am basically trying to multiply two values but every time I run my emulator and click on the button (calculate) it crashes:</p>
  
  <p><strong>Java Code:</strong></p>
  
  <pre><code> package com.example.cantcook;
  
   import java.math.BigDecimal;
  
   import android.app.Activity;
   import android.os.Bundle;
   import android.view.Menu;
   import android.view.View;
   import android.widget.Button;
   import android.widget.EditText;
   import android.widget.TextView;
  
  public class Calculator extends Activity {
      EditText costofmeal, amountofpeople;
      TextView costperperson;
      Button Calculate;
      BigDecimal costNum, percentNum;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_calculator);
  
          costofmeal = (EditText) findViewById(R.id.editText1); 
          amountofpeople = (EditText) findViewById(R.id.editText2);
  
          Calculate = (Button) findViewById(R.id.button1);
  
          costperperson = (TextView) findViewById(R.id.textView2);
          //costperperson.setText("£0.00");
  
  
          Calculate.setOnClickListener(new View.OnClickListener()
          {
  
          public void onClick (View v)
          {
              costNum = new BigDecimal(costofmeal.getText().toString());
              percentNum = new BigDecimal(amountofpeople.getText().toString());
              costperperson.setText(costNum.multiply(percentNum).toString());
          }
          });
      }
  </code></pre>
  
  <p><strong>XML code:</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/background"
      tools:context=".Calculator" &gt;
  
      &lt;TextView
          android:id="@+id/textView2"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="25dp"
          android:text="£"
          android:textAlignment="center"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_marginTop="112dp"
          android:text="  Total spent on Shopping"
          android:textAlignment="center"
          android:textSize="18dp"
          android:textStyle="bold"
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
      &lt;TextView
          android:id="@+id/textView3"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_centerVertical="true"
          android:text="  Amount of People"
          android:textAlignment="center"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:textSize="18dp"
          android:textStyle="bold" /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/textView2"
          android:layout_alignParentRight="true"
          android:layout_marginBottom="25dp"
          android:onClick="Btncalculate"
          android:text="Calculate" /&gt;
  
      &lt;EditText
          android:id="@+id/editText2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/textView3"
          android:layout_marginTop="22dp"
          android:ems="10"
          android:inputType="numberSigned" /&gt;
  
      &lt;EditText
          android:id="@+id/editText1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/textView1"
          android:layout_marginTop="17dp"
          android:ems="10"
          android:inputType="numberDecimal"
          android:text="£" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>