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 8029493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:27:14+00:00 2026-06-05T00:27:14+00:00

This is logcat. My program is Calculator, I don’t know how to solve this

  • 0

This is logcat. My program is Calculator, I don’t know how to solve this mistake

E/AndroidRuntime(620): java.lang.RuntimeException: Unable to start activity ComponentInfo{calculator.tt/calculator.tt.CalculatorActivity}: java.lang.ClassCastException: android.widget.EditText cannot be cast to android.widget.Button

This is main.xml file, My layout has a edittext and 5 tablerow. In the last tablerow I make equal button bigger than another button.

<?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:orientation="vertical" >



        <EditText
            android:id="@+id/answer"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:ems="10"
            android:gravity="right|center|end"
            android:lines="1" >

            <requestFocus />
        </EditText>


        <TableRow
            android:id="@+id/TableRow02"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:paddingLeft="5dp"
            android:paddingTop="30dp" >

            <Button
                android:id="@+id/open"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="(" />

            <Button
                android:id="@+id/close"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text=")" />


            <ImageButton
                android:id="@+id/sqrt"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:src="@drawable/sqrt" />

            <Button
                android:id="@+id/add"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="+" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp" >



            <ImageButton
                android:id="@+id/x2"
                android:layout_width="77dp"
                android:layout_height="match_parent"
                android:src="@drawable/x2" />


            <ImageButton
                android:id="@+id/x3"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:src="@drawable/x3" />


            <Button
                android:id="@+id/giaithua"
                android:layout_width="77dp"
                android:layout_height="match_parent"
                android:text="x!" />


            <Button
                android:id="@+id/sub"
                android:layout_width="77dp"
                android:layout_height="match_parent"
                android:text="-" />

        </TableRow>

        <TableRow
            android:id="@+id/TableRow03"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp" >

            <Button
                android:id="@+id/key7"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="7" />

            <Button
                android:id="@+id/key8"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="8" />

            <Button
                android:id="@+id/key9"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="9" />

            <Button
                android:id="@+id/mul"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="*" />
        </TableRow>

        <TableRow
            android:id="@+id/TableRow04"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp" >

            <Button
                android:id="@+id/key4"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="4" />

            <Button
                android:id="@+id/key5"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="5" />

            <Button
                android:id="@+id/key6"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="6" />

            <Button
                android:id="@+id/div"
                android:layout_width="77dp"
                android:layout_height="wrap_content"
                android:text="/" />
        </TableRow>

        <TableRow
            android:id="@+id/TableRow05"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp" >

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

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <Button
                        android:id="@+id/key1"
                        android:layout_width="77dp"
                        android:layout_height="wrap_content"
                        android:text="1" />

                    <Button
                        android:id="@+id/key2"
                        android:layout_width="77dp"
                        android:layout_height="wrap_content"
                        android:text="2" />

                    <Button
                        android:id="@+id/key3"
                        android:layout_width="77dp"
                        android:layout_height="wrap_content"
                        android:text="3" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >

                    <Button
                        android:id="@+id/dot"
                        android:layout_width="77dp"
                        android:layout_height="wrap_content"
                        android:text="." />

                    <Button
                        android:id="@+id/key0"
                        android:layout_width="77dp"
                        android:layout_height="wrap_content"
                        android:text="0" />


                    <ImageButton
                        android:id="@+id/minus"
                        android:layout_width="77dp"
                        android:layout_height="match_parent"
                        android:src="@drawable/minus" />

                </LinearLayout>
            </LinearLayout>

            <Button
                android:id="@+id/Equal"
                android:layout_width="77dp"
                android:layout_height="95dp"
                android:text="=" />
        </TableRow>

    </LinearLayout>

This is CalculatorActivity:

package calculator.tt;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;


public class CalculatorActivity extends Activity {

    EditText answer1;
    String as;
    char c;
    double a, b, e;
    boolean k;
    Button addbutton;
    Button subbutton;
    Button divbutton;
    Button mulbutton;
    ImageButton x2button;
    ImageButton x3button;
    ImageButton sqrtbutton;
    Button gtbutton;
    Button opbutton;
    Button clbutton;
    Button dotbutton;
    ImageButton minusbutton;
    Button key0button;
    Button key1button;
    Button key2button;
    Button key3button;
    Button key4button;
    Button key5button;
    Button key6button;
    Button key7button;
    Button key8button;
    Button key9button;
    Button equalbutton;

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

        /*Khai báo các lớp cho các button*/
        answer1 = (EditText)findViewById(R.id.answer);
        answer1.setInputType(InputType.TYPE_NULL);

        addbutton = (Button)findViewById(R.id.add);
        addbutton.setOnClickListener(new AddbuttonHandler());

        subbutton = (Button)findViewById(R.id.sub);
        subbutton.setOnClickListener(new SubbuttonHandler());

        divbutton = (Button)findViewById(R.id.div);
        divbutton.setOnClickListener(new DivbuttonHandler());

        mulbutton = (Button)findViewById(R.id.mul);
        mulbutton.setOnClickListener(new MulbuttonHandler());

        equalbutton = (Button)findViewById(R.id.answer);
        equalbutton.setOnClickListener(new EqualbuttonHandler());

        sqrtbutton = (ImageButton)findViewById(R.id.sqrt);
        sqrtbutton.setOnClickListener(new SqrtbuttonHandler());

        x2button = (ImageButton)findViewById(R.id.x2);
        x2button.setOnClickListener(new X2buttonHandler());

        x3button = (ImageButton)findViewById(R.id.x3);
        x3button.setOnClickListener(new X3buttonHandler());

        minusbutton = (ImageButton)findViewById(R.id.minus);
        minusbutton.setOnClickListener(new MinusbuttonHandler());

        gtbutton = (Button)findViewById(R.id.giaithua);
        gtbutton.setOnClickListener(new GtbuttonHandler());

        dotbutton = (Button)findViewById(R.id.dot);
        dotbutton.setOnClickListener(new DotbuttonHandler());

        key0button = (Button)findViewById(R.id.key0);
        key0button.setOnClickListener(new key0buttonHandler());

        key1button = (Button)findViewById(R.id.key1);
        key1button.setOnClickListener(new key1buttonHandler()); 

        key2button = (Button)findViewById(R.id.key2);
        key2button.setOnClickListener(new key2buttonHandler()); 

        key3button = (Button)findViewById(R.id.key3);
        key3button.setOnClickListener(new key3buttonHandler()); 

        key4button = (Button)findViewById(R.id.key4);
        key4button.setOnClickListener(new key4buttonHandler()); 

        key5button = (Button)findViewById(R.id.key5);
        key5button.setOnClickListener(new key5buttonHandler()); 

        key6button = (Button)findViewById(R.id.key6);
        key6button.setOnClickListener(new key6buttonHandler()); 

        key7button = (Button)findViewById(R.id.key7);
        key7button.setOnClickListener(new key7buttonHandler());

        key8button = (Button)findViewById(R.id.key8);
        key8button.setOnClickListener(new key8buttonHandler()); 

        key9button = (Button)findViewById(R.id.key9);
        key9button.setOnClickListener(new key9buttonHandler());
        Log.e("Đang chạy đến đây","Xong khai bao cac lop");
    }
    /* Các lớp cho button*/
    private class X2buttonHandler implements OnClickListener{
        public void onClick (View v){
            k=true;
            a = Double.parseDouble(answer1.getText().toString());
            answer1.setText(a*a+"");

        }
    }
    private class X3buttonHandler implements OnClickListener{
        public void onClick (View v){
            k=true;
            a = Double.parseDouble(answer1.getText().toString());
            answer1.setText(a*a*a+"");
        }
    }
    private class MinusbuttonHandler implements OnClickListener{
        public void onClick (View v){
            a = Double.parseDouble(answer1.getText().toString());
            answer1.setText(-a+"");
        }
    }
    /*Tính căn bậc 2*/
    private class SqrtbuttonHandler implements OnClickListener{
        public void onClick (View v){
            k=true;
            a = Double.parseDouble(answer1.getText().toString());
            b = Math.sqrt(a);
            answer1.setText(b+"");
        }
    }
    /*Tinh giai thua*/
    private class GtbuttonHandler implements OnClickListener{
        public void onClick (View v){
            k=true;
            a = Double.parseDouble(answer1.getText().toString());
            b=1;
            for (int i=1;i<a+1;i++)
                {
                b=b*i;
                }
            answer1.setText(b+"");
        }
    }

    private class DotbuttonHandler implements OnClickListener{
        public void onClick (View v){
            int i;
            as = answer1.getText().toString();
            if (k)
                answer1.setText("");
            k=false;
            /*Chi cho duy nhat 1 dau cham xuat hien*/
            for (i=0;i<as.length();i++)             
                if(as.charAt(i)==46)
                { i=1;
                  break;
                }
            if (i!=1)
                answer1.append("."); 
        }
    }
    private class key0buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");
            answer1.append("0");
            k=false;
        }
    }
    private class key1buttonHandler implements OnClickListener{
        public void onClick (View v){               
            if (k)
                answer1.setText("");    
            answer1.append("1");
            k=false;
        }
    }
    private class key2buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");        
            answer1.append("2");
            k=false;
        }
    }
    private class key3buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");
            answer1.append("3");
            k=false;
        }
    }
    private class key4buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");
            answer1.append("4");
            k=false;
        }
    }
    private class key5buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");
            answer1.append("5");
            k=false;
        }
    }
    private class key6buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");
            answer1.append("6");
            k=false;
        }
    }
    private class key7buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");
            answer1.append("7");
            k=false;
        }
    }
    private class key8buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");
            answer1.append("8");
            k=false;
        }
    }
    private class key9buttonHandler implements OnClickListener{
        public void onClick (View v){
            if (k)
                answer1.setText("");
            answer1.append("9");
            k=false;
        }
    }

    private class AddbuttonHandler implements OnClickListener{
        public void onClick (View v){
            int i,z=0;
            String a1=null,a2=null;
            for (i=0;i<as.length();i++)
                if (as.charAt(i)==43||as.charAt(i)==42||as.charAt(i)==45||as.charAt(i)==47){
                        a1 = as.substring(0,i-1);
                        a2 = as.substring(i+1,as.length());
                        z=as.charAt(i);
                        break;
                    }
            a = Double.parseDouble(a1);
            b = Double.parseDouble(a2);
            if (z==43)
                answer1.setText(a+b + "");
            if (z==42)
                answer1.setText(a*b + "");
            if (z==45)
                answer1.setText(a-b + "");
            else answer1.setText(a/b + "");
            answer1.append("+");
    }
}
    private class MulbuttonHandler implements OnClickListener{
        public void onClick (View v){
            int i,z=0;
            String a1=null,a2=null;
            for (i=0;i<as.length();i++)
                if (as.charAt(i)==43||as.charAt(i)==42||as.charAt(i)==45||as.charAt(i)==47){
                        a1 = as.substring(0,i-1);
                        a2 = as.substring(i+1,as.length());
                        z=as.charAt(i);
                        break;
                    }
            a = Double.parseDouble(a1);
            b = Double.parseDouble(a2);
            if (z==43)
                answer1.setText(a+b + "");
            if (z==42)
                answer1.setText(a*b + "");
            if (z==45)
                answer1.setText(a-b + "");
            else answer1.setText(a/b + "");
            answer1.append("*");
        }
    }
    private class SubbuttonHandler implements OnClickListener{
        public void onClick (View v){
            int i,z=0;
            String a1=null,a2=null;
            for (i=0;i<as.length();i++)
                if (as.charAt(i)==43||as.charAt(i)==42||as.charAt(i)==45||as.charAt(i)==47){
                        a1 = as.substring(0,i-1);
                        a2 = as.substring(i+1,as.length());
                        z=as.charAt(i);
                        break;
                    }
            a = Double.parseDouble(a1);
            b = Double.parseDouble(a2);
            if (z==43)
                answer1.setText(a+b + "");
            if (z==42)
                answer1.setText(a*b + "");
            if (z==45)
                answer1.setText(a-b + "");
            else answer1.setText(a/b + "");
            answer1.append("-");
        }
    }
    private class DivbuttonHandler implements OnClickListener{
        public void onClick (View v){
            int i,z=0;
            String a1=null,a2=null;
            for (i=0;i<as.length();i++)
                if (as.charAt(i)==43||as.charAt(i)==42||as.charAt(i)==45||as.charAt(i)==47){
                        a1 = as.substring(0,i-1);
                        a2 = as.substring(i+1,as.length());
                        z=as.charAt(i);
                        break;
                    }
            a = Double.parseDouble(a1);
            b = Double.parseDouble(a2);
            if (z==43)
                answer1.setText(a+b + "");
            if (z==42)
                answer1.setText(a*b + "");
            if (z==45)
                answer1.setText(a-b + "");
            else answer1.setText(a/b + "");
            answer1.append("/");
        }
    }
    private class EqualbuttonHandler implements OnClickListener{
        public void onClick (View v){
            int i,z=0;
            String a1 = null, a2 = null;
            k=true;
            as = answer1.getText().toString();
            for (i=0;i<as.length();i++)
                if (as.charAt(i)==43||as.charAt(i)==42||as.charAt(i)==45||as.charAt(i)==47){
                        a1 = as.substring(0,i-1);
                        a2 = as.substring(i+1,as.length());
                        z=as.charAt(i);
                        break;
                    }
            a = Double.parseDouble(a1);
            b = Double.parseDouble(a2);
            if (z==43)
                answer1.setText(a+b + "");
            if (z==42)
                answer1.setText(a*b + "");
            if (z==45)
                answer1.setText(a-b + "");
            else answer1.setText(a/b + "");
            }
        }
    }
  • 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-05T00:27:16+00:00Added an answer on June 5, 2026 at 12:27 am

    In this Java line:
    equalbutton = (Button)findViewById(R.id.answer);

    You are looking up an EditText defined by this XML:
    <EditText
            android:id=”@+id/answer”

    It looks like you meant to write this:
    equalbutton = (Button)findViewById(R.id.Equal);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this in LogCat: 05-20 17:16:34.721: E/AndroidRuntime(30461): FATAL EXCEPTION: main 05-20 17:16:34.721:
I am getting this exception in the LogCat: Unable to start service Intent {
Well, my program keeps giveing me a null point exception and I don't know
This is the error occurs in logcat,can anyone tell what's the meaning? private int
I have got this logcat error more then one time. This time I started
I don't know where to turn, i was following an android tutorial here and
This is the error my logcat is giving me. I understand it has something
Why does this c++ (NDK) thread brings the whole program down ? { sleep(2);
After running the program, Logcat shows some errors (picture). But after that program runs
I have a paint program that has no save function. I want to know

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.