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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:18:12+00:00 2026-05-31T09:18:12+00:00

I have an activity that force closes and i get a logcat error. It

  • 0

I have an activity that force closes and i get a logcat error. It is a simple calculator activity it worked 5 minutes ago here is the logcat:

03-04 14:14:57.292: D/dalvikvm(14349): GC_EXTERNAL_ALLOC freed 47K, 49% free 2793K/5379K, external 1596K/2108K, paused 100ms
03-04 14:14:57.492: D/dalvikvm(14349): GC_EXTERNAL_ALLOC freed 1K, 49% free 2792K/5379K, external 3471K/4335K, paused 75ms
03-04 14:14:58.160: D/dalvikvm(14349): GC_EXTERNAL_ALLOC freed <1K, 49% free 2794K/5379K, external 5048K/5580K, paused 132ms
03-04 14:14:58.453: D/dalvikvm(14349): GC_EXTERNAL_ALLOC freed <1K, 49% free 2795K/5379K, external 8143K/8403K, paused 50ms
03-04 14:15:02.945: D/AndroidRuntime(14349): Shutting down VM
03-04 14:15:02.945: W/dalvikvm(14349): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-04 14:15:02.972: E/AndroidRuntime(14349): FATAL EXCEPTION: main
03-04 14:15:02.972: E/AndroidRuntime(14349): java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.calculator}: java.lang.ClassCastException: android.widget.Button
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.os.Looper.loop(Looper.java:130)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.app.ActivityThread.main(ActivityThread.java:3687)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at java.lang.reflect.Method.invokeNative(Native Method)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at java.lang.reflect.Method.invoke(Method.java:507)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at dalvik.system.NativeStart.main(Native Method)
03-04 14:15:02.972: E/AndroidRuntime(14349): Caused by: java.lang.ClassCastException: android.widget.Button
03-04 14:15:02.972: E/AndroidRuntime(14349):    at izzy.n.calculator.onCreate(calculator.java:24)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-04 14:15:02.972: E/AndroidRuntime(14349):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-04 14:15:02.972: E/AndroidRuntime(14349):    ... 11 more
03-04 14:19:11.265: D/dalvikvm(14411): GC_EXTERNAL_ALLOC freed 50K, 49% free 2793K/5379K, external 1596K/2108K, paused 136ms
03-04 14:19:11.320: D/dalvikvm(14411): GC_EXTERNAL_ALLOC freed 1K, 49% free 2792K/5379K, external 3471K/4335K, paused 18ms
03-04 14:19:11.570: D/dalvikvm(14411): GC_EXTERNAL_ALLOC freed <1K, 49% free 2794K/5379K, external 5048K/5580K, paused 19ms
03-04 14:19:12.152: D/dalvikvm(14411): GC_EXTERNAL_ALLOC freed <1K, 49% free 2795K/5379K, external 8143K/8403K, paused 19ms
03-04 14:19:47.945: D/AndroidRuntime(14411): Shutting down VM
03-04 14:19:47.945: W/dalvikvm(14411): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-04 14:19:47.960: E/AndroidRuntime(14411): FATAL EXCEPTION: main
03-04 14:19:47.960: E/AndroidRuntime(14411): java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.calculator}: java.lang.ClassCastException: android.widget.Button
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.os.Looper.loop(Looper.java:130)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.app.ActivityThread.main(ActivityThread.java:3687)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at java.lang.reflect.Method.invokeNative(Native Method)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at java.lang.reflect.Method.invoke(Method.java:507)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at dalvik.system.NativeStart.main(Native Method)
03-04 14:19:47.960: E/AndroidRuntime(14411): Caused by: java.lang.ClassCastException: android.widget.Button
03-04 14:19:47.960: E/AndroidRuntime(14411):    at izzy.n.calculator.onCreate(calculator.java:24)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-04 14:19:47.960: E/AndroidRuntime(14411):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-04 14:19:47.960: E/AndroidRuntime(14411):    ... 11 more

and here is calculator.java (which has no errors in eclipse):

public class calculator extends Activity {
        private EditText input1;
        private EditText input2;
        private EditText solution;
        private TextView operator;
        private calculator mContext;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.calc);

                input1 = (EditText) findViewById(R.id.input1);
                input2 = (EditText) findViewById(R.id.input2);
                solution = (EditText) findViewById(R.id.solution);
                operator = (TextView) findViewById(R.id.operator);

                // We create an OnClick Event in each button.

                Button plusButton = (Button) findViewById(R.id.plusbutton);
                Button minusButton = (Button) findViewById(R.id.minusbutton);
                Button prodButton = (Button) findViewById(R.id.prodbutton);
                Button divButton = (Button) findViewById(R.id.divbutton);
                Button equalButton = (Button) findViewById(R.id.equalbutton);

                plusButton.setOnClickListener(new OnClickListener() {

                        public void onClick(View arg0) {

                                operator.setText("+");

                        }

                });

                minusButton.setOnClickListener(new OnClickListener() {

                        public void onClick(View arg0) {

                                operator.setText("-");

                        }

                });

                prodButton.setOnClickListener(new OnClickListener() {

                        public void onClick(View arg0) {

                                operator.setText("*");

                        }

                });

                divButton.setOnClickListener(new OnClickListener() {

                        public void onClick(View arg0) {

                                operator.setText("/");

                        }

                });

                equalButton.setOnClickListener(new OnClickListener() {

                        private AlertDialog show;

                        public void onClick(View arg0) {

                                if ((input1.getText().length() == 0)
                                                || (input1.getText().toString() == " ")
                                                || (input2.getText().length() == 0)
                                                || (input2.getText().toString() == " ")) {

                                        show = new AlertDialog.Builder(mContext).setTitle("Error")
                                                        .setMessage("Some inputs are empty")
                                                        .setPositiveButton("OK", null).show();

                                } else if (operator.getText().equals("")) {

                                        show = new AlertDialog.Builder(mContext).setTitle("Error")
                                                        .setMessage("Operator is null").setPositiveButton(
                                                                        "OK", null).show();

                                } else if (operator.getText().equals("+")) {

                                        double result = new Double(input1.getText().toString())
                                                        + new Double(input2.getText().toString());

                                        solution.setText(Double.toString(result));

                                } else if (operator.getText().equals("-")) {

                                        double result = new Double(input1.getText().toString())
                                                        - new Double(input2.getText().toString());

                                        solution.setText(Double.toString(result));

                                } else if (operator.getText().equals("*")) {

                                        double result = new Double(input1.getText().toString())
                                                        * new Double(input2.getText().toString());

                                        solution.setText(Double.toString(result));

                                } else if (operator.getText().equals("/")) {


                                        double result = new Double(input1.getText().toString())
                                                        / new Double(input2.getText().toString());

                                        solution.setText(Double.toString(result));

                                }

                        }

                });

        }

}

Here is the main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/gray" >

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="40dp"
        android:src="@drawable/notes" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="165dp"
        android:layout_height="165dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="-2dp"
        android:layout_marginTop="20dp"
        android:src="@drawable/calc" />

    <Button
        android:id="@+id/button10"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_alignLeft="@+id/imageView3"
        android:layout_alignTop="@+id/imageView2"
        android:layout_marginLeft="19dp"
        android:background="@null" />

    <Button
        android:id="@+id/button1"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_alignLeft="@+id/imageView2"
        android:layout_alignTop="@+id/imageView2"
        android:background="@null" />

</RelativeLayout>

calc.xml:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/widget45"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <Button android:id="@+id/divbutton" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="/"
                android:layout_x="192px" android:layout_y="86px">
        </Button>
        <Button android:id="@+id/minusbutton" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="-"
                android:layout_x="254px" android:layout_y="18px">
        </Button>
        <EditText android:id="@+id/input1" android:layout_width="160px"
                android:layout_height="wrap_content" android:textSize="18sp"

                android:numeric = "decimal|signed"
                android:layout_x="8px" android:layout_y="13px">
        </EditText>
        <EditText android:id="@+id/input2" android:layout_width="156px"
                android:layout_height="wrap_content" android:textSize="18sp"
                android:numeric = "decimal|signed"
                android:layout_x="10px" android:layout_y="109px">
        </EditText>
        <Button android:id="@+id/plusbutton" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="+"
                android:layout_x="193px" android:layout_y="19px">
        </Button>
        <TextView android:id="@+id/operator" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_x="33px"
                android:layout_y="77px">
        </TextView>
        <EditText android:id="@+id/solution" android:layout_width="304px"
                android:layout_height="wrap_content" android:textSize="18sp"
                android:layout_x="7px" android:layout_y="214px">
        </EditText>
        <Button android:id="@+id/prodbutton" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="*"
                android:layout_x="253px" android:layout_y="87px">
        </Button>
        <Button android:id="@+id/equalbutton" android:layout_width="120px"
                android:layout_height="wrap_content" android:text="="
                android:layout_x="192px" android:layout_y="149px">
        </Button>
</AbsoluteLayout>
  • 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-05-31T09:18:14+00:00Added an answer on May 31, 2026 at 9:18 am

    You’re issue is here:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.calculator}: java.lang.ClassCastException: android.widget.Button

    What it means, is that you are casting something to a Button which isn’t a Button.
    If you go to your XML file, check which one of these isn’t a Button.

    Perhaps you used ImageButton instead? It needs changing to just Button if you did.

                Button plusButton = (Button) findViewById(R.id.plusbutton);
                Button minusButton = (Button) findViewById(R.id.minusbutton);
                Button prodButton = (Button) findViewById(R.id.prodbutton);
                Button divButton = (Button) findViewById(R.id.divbutton);
                Button equalButton = (Button) findViewById(R.id.equalbutton);
    

    If this isn’t your fix, please post up your XML document R.layout.calc.

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

Sidebar

Related Questions

This seems like a simple problem: I have a WF4 activity that guides the
So I have a very simple android activity that starts a timer when you
I have a weird issue. I receive the following error that causes a force-close:
Ok I have a simple main activity that just presents the user with a
I have worked on a simple application. It application includes diffrent levels that can
I have an activity that has a TabHost containing a set of TabSpecs each
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an activity that launches another activity with startActivityForResult method. I would like
i have created a workflow activity that do give the item creater of a
I have created a custom workflow activity that copies attachments from a case to

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.