Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:23:04+00:00 2026-06-18T11:23:04+00:00

I have a simple application to multiply two numbers from text boxes and display

  • 0

I have a simple application to multiply two numbers from text boxes and display result in third box. There is no any syntax errors in the code but when I am running an application i get this error: application has stopped unexpectedly.

Here is the java code:

package c.example.rectangle;

import android.os.Bundle;

import android.view.View;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{

    EditText l = (EditText) findViewById(R.id.length);
    EditText w = (EditText) findViewById(R.id.width);
    TextView a = (TextView) findViewById(R.id.lblarea);
    Button b = (Button) findViewById(R.id.calculate);


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);  
        b.setOnClickListener(this);

    }

    public void onClick(View v) {
        calculateRectangle(l.getText().toString(), w.getText().toString());


    }
    private void calculateRectangle(String clength, String cwidth){


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

        b.setText(String.valueOf(area)); 
}}

And here is my XML file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#8B4513"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/label1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:background="#2F4F4F"
        android:gravity="center"
        android:text="@string/rect"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#8B4513"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/label2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="50dp"
            android:background="#2F4F4F"
            android:gravity="center"
            android:text="@string/cm"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/length"
            android:layout_width="110dp"
            android:layout_height="21dp"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="50dp"
            android:background="#2F4F4F"
            android:ems="10"
            android:gravity="center"
            android:inputType="number" />


    </LinearLayout>

 <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#8B4513"
        android:orientation="horizontal" >

    <TextView
        android:id="@+id/label3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#2F4F4F"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:text="@string/breadth"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/width"
        android:layout_width="110dp"
        android:layout_height="21dp"
        android:layout_marginLeft="33dp"
        android:layout_marginTop="20dp"   
        android:background="#2F4F4F"
        android:inputType="number"
        android:ems="10" 
        android:gravity="center"
        >

        <requestFocus />
    </EditText>

</LinearLayout>

 <Button
     android:id="@+id/calculate"
     android:layout_width="fill_parent"
     android:layout_marginLeft="100dip"
     android:layout_marginRight="100dip"
     android:layout_height="wrap_content"
     android:text="@string/calculate"
     android:layout_marginTop="20dp" />

 <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#8B4513"
        android:orientation="horizontal" >

 <TextView
     android:id="@+id/label4"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_marginLeft="30dp"
     android:layout_marginTop="20dp"
     android:background="#2F4F4F"
     android:text="@string/area"
     android:textAppearance="?android:attr/textAppearanceMedium" />

 <TextView
     android:id="@+id/lblarea"
     android:layout_width="110dp"
     android:layout_height="21dp"
     android:layout_marginLeft="60dp"
     android:layout_marginTop="20dp"
     android:background="#2F4F4F"
     android:gravity="center"/>
 </LinearLayout>
  </LinearLayout>

Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:23:05+00:00Added an answer on June 18, 2026 at 11:23 am

    Rearrange your code to look like this:

     EditText l;
     EditText w;
     TextView a;
     Button b;
    
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 
        l = (EditText) findViewById(R.id.length);
        w = (EditText) findViewById(R.id.width);
        a = (TextView) findViewById(R.id.lblarea);
        b = (Button) findViewById(R.id.calculate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple application which takes a text and password, generates a text
I have this simple MVC 3 application which simply has two controllers(Home and Edit),
In my application, I have two lists of sounds from different categories and a
I have a simple application which spawns two threads and assigns one with a
I'm writing a simple membership application. I have two models, Member and Membership .
I have an application that uses simple sockets to pass some characters between two
Very simple Qt GUI application: On the scene I have multiple circles implemented as
I have simple WinForms application where modifying Windows Registry. The problem is that in
I have a simple application that loads an unmanaged dll and passes a few
I have a simple application in which I need to let the user select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.