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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:53:43+00:00 2026-06-17T07:53:43+00:00

Android 2.3.3 I am working on a custom calculator. I am trying the change

  • 0

Android 2.3.3

I am working on a custom calculator. I am trying the change the UI, just shuffling around the buttons and particularly, i get the ClassCastException when i try to change one button.
I tried “Clean”ing the project, deleting the R.java file, changing the xml file and saving, but none worked. Here is the error stack from eclipse :::

01-10 09:19:41.949: E/AndroidRuntime(21494): FATAL EXCEPTION: main
01-10 09:19:41.949: E/AndroidRuntime(21494): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobilevoiceapps.advancedvoicecalculatorplus/com.mobilevoiceapps.advancedvoicecalculatorplus.AdvancedVoiceCalculatorPlus}: java.lang.ClassCastException: android.widget.LinearLayout
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.os.Looper.loop(Looper.java:130)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.app.ActivityThread.main(ActivityThread.java:3687)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at java.lang.reflect.Method.invokeNative(Native Method)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at java.lang.reflect.Method.invoke(Method.java:507)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at dalvik.system.NativeStart.main(Native Method)
01-10 09:19:41.949: E/AndroidRuntime(21494): Caused by: java.lang.ClassCastException: android.widget.LinearLayout
01-10 09:19:41.949: E/AndroidRuntime(21494):    at com.mobilevoiceapps.advancedvoicecalculatorplus.AdvancedVoiceCalculatorPlus.onCreate(AdvancedVoiceCalculatorPlus.java:226)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-10 09:19:41.949: E/AndroidRuntime(21494):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-10 09:19:41.949: E/AndroidRuntime(21494):    ... 11 more

Here is the xml file without any errors:::

   <LinearLayout
                android:id="@+id/linearLayout9"
                android:layout_width="match_parent"
                android:layout_height="45px"
                android:layout_marginBottom="2px"
                android:background="#000000" >

                <Button
                    android:id="@+id/btnPower"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="^"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />



                <Button
                    android:id="@+id/btnNthRoot"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="n √x"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />



                <Button
                    android:id="@+id/btnLog10"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="Log10"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />

                <Button
                    android:id="@+id/btnLN"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="Loge"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />
            </LinearLayout>

When i change the power button to a different linear layout, the error occurs…

XML when error occurs

 <LinearLayout
                android:id="@+id/linearLayout4"
                android:layout_width="match_parent"
                android:layout_height="45px"
                android:layout_marginBottom="2px"
                android:background="#000000" >

                <Button
                    android:id="@+id/btnInverse"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="1/x"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />





                <Button
                    android:id="@+id/btnFactorial"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="n!"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />


                <Button
                    android:id="@+id/btnPower"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="^"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />


                <Button
                    android:id="@+id/btnPercentage"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="%"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />

                <Button
                    android:id="@+id/btnNumberLeftBrace"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text="("
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />

                <Button
                    android:id="@+id/btnNumberRightBrace"
                    android:layout_width="0dip"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="2px"
                    android:layout_weight="0.20"
                    android:background="@drawable/button_custom"
                    android:text=")"
                    android:textColor="#FFFFFF"
                    android:textSize="24px" />
            </LinearLayout>

When i try to change the power(id/btnPower) button, i get the classcastexception. If i replace it in the linearlayout9(id/linearlayout9) then the error disappears. It compiles well, but at runtime, it will give an exception.

            btn0 = (Button) findViewById(R.id.btnNumber0);
        btn1 = (Button) findViewById(R.id.btnNumber1); // line with the error
        btn2 = (Button) findViewById(R.id.btnNumber2);
        btn3 = (Button) findViewById(R.id.btnNumber3);
        btn4 = (Button) findViewById(R.id.btnNumber4);
        btn5 = (Button) findViewById(R.id.btnNumber5);
        btn6 = (Button) findViewById(R.id.btnNumber6);

The error is not at a constant place. It depends on where i insert the power button. I did read quite a few questions on ClassCastException, but i didn’t quite understand why is it being caused. I will be glad if someone can explain it in detail.

Please let me know, if you need any other information.

[SOLVED] Uninstall the application from the mobile, go to project->clean and run again. If the error keeps coming, do follow the steps again. Thanks for the 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-17T07:53:44+00:00Added an answer on June 17, 2026 at 7:53 am

    As I already experienced this issue, and lost a lot of time on it, this is just what I did:

    • Uninstall the app from phone/emulator
    • (clean might help – not sure)
    • re-compile and install a fresh version of your app.

    A simple clean does not seems to help, the uninstall is more likely to delete strangeness and fix the issue.

    Hope this can help.

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

Sidebar

Related Questions

I am working on one custom video player in android. I am using VideoView
I'm trying to get a custom adapter working with XML Inflater, though I get
I am trying to use Android's LocationManager requestLocationUpdates. Everything is working until I try
I am currently working on android project where I am using a custom list
Is there any way, how to get new x86 image for Android emulator working
i am working on android and trying to read a value from my preference
I'm working with Android and I really need a fast way to get a
I've been working on my android calculator and i can't seem to insert an
I have a working custom search suggestions class (via http://developer.android.com/guide/topics/search/adding-custom-suggestions.html ). It currently returns
I'm working on a custom ROM and I'm receiving this error while trying 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.