Simple rectangle area calculation crash
<p>I'm new to android and am currently attempting to create a simple application which calculates the area of a rectangle.</p>

<p>When the calculation is performed, the result is shown on the TextView specified.</p>

<p>This is my current code for calculating the area of the rectangle:</p>

<p><code></p>

<pre><code>package org.me.myandroidstuff;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
import android.app.Activity;
import android.os.Bundle;

public class CalculateRectangleArea2Activity extends Activity implements OnClickListener{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        EditText length = (EditText) findViewById(R.id.txtLength);
        EditText width = (EditText) findViewById(R.id.txtWidth);
        TextView result = (TextView) findViewById(R.id.lblResult);
        Button calculate = (Button) findViewById(R.id.btnCalculate);

        calculate.setOnClickListener(this);
    }

    public void onClick(View v){

        EditText length = (EditText) findViewById(R.id.txtLength);
        EditText width = (EditText) findViewById(R.id.txtWidth);
        calculateArea(length.getText().toString(), width.getText().toString());     
    }

    private void calculateArea(String clength, String cwidth){

        TextView result = (TextView) findViewById(R.id.lblResult);

        int area = Integer.parseInt(clength)*Integer.parseInt(cwidth);

        result.setText(area);
    }}
</code></pre>

<p></code></p>

<p>Here is my main.xml file:</p>

<p><code></p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" &gt;

    &lt;EditText
        android:id="@+id/txtLength"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="number"/&gt;

    &lt;EditText
        android:id="@+id/txtWidth"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="number"/&gt;

    &lt;TextView 
        android:id="@+id/lblResult"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/&gt;

    &lt;Button
        android:id="@+id/btnCalculate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/&gt;

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

<p></code></p>

<p>When clicking the button to calculate, the application has the error "The application calculateRectangleArea2  has stopped unexpectedly. Please try again." </p>

<p>I believe this has something to do with NullPointerException, though attempting to trace the error through logCat and breakpoints hasn't helped.</p>

<p>Any help would be hugely appreciated :), thanks!</p>
