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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:47:18+00:00 2026-06-06T05:47:18+00:00

I have had this problem crop up a few times and I can’t figure

  • 0

I have had this problem crop up a few times and I can’t figure out why it should happen. What happened was after moving some stuff around my TextView box ended up on top of an EditText box, which is no good. So I went and moved the TextView box to the bottom of the screen. When I did that, the app would crash when I tried to access the piggybank. However, if I move the TextView box up to the top again, it works fine.. I really don’t get it. Anyways, this is the error that I got

06-22 09:06:41.928: E/AndroidRuntime(10958): java.lang.RuntimeException: Unable to
 start activity ComponentInfo{net.finalexam/net.finalexam.Piggy}: 
 java.lang.ClassCastException: android.widget.RadioButton

This is piggy xml file

    <?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/piggy" >

    <EditText
        android:id="@+id/txtQuarters"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="27dp"
        android:ems="10"
        android:hint="Number of quarters"
        android:inputType="number" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/txtDimes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtQuarters"
        android:layout_centerHorizontal="true"
        android:ems="10"
        android:hint="Number of dimes"
        android:inputType="number" />

    <EditText
        android:id="@+id/txtNickles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtDimes"
        android:layout_centerHorizontal="true"
        android:ems="10"
        android:hint="Number of nickles"
        android:inputType="number" />

    <EditText
        android:id="@+id/txtPennies"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtNickles"
        android:layout_centerHorizontal="true"
        android:ems="10"
        android:hint="Number of pennies"
        android:inputType="number" />


    <EditText
        android:id="@+id/txtDollars"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtPennies"
        android:layout_centerHorizontal="true"
        android:ems="10"
        android:hint="Number of Dollars"
        android:inputType="number" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtDollars"
        android:layout_centerHorizontal="true" >

        <RadioButton
            android:id="@+id/radAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Add" />

        <RadioButton
            android:id="@+id/radSubtract"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Subtract" />
    </RadioGroup>

    <Button
        android:id="@+id/btnCalculate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/radioGroup1"
        android:layout_centerHorizontal="true"
        android:text="Calculate" />

    <TextView
        android:id="@+id/txtResults"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnCalculate"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="27dp"
        android:textSize="40sp" android:textStyle="bold" android:textColor="#000000"/>

</RelativeLayout>

This is the Piggy Java file

package net.finalexam;

import java.text.DecimalFormat;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class Piggy extends Activity
{
  double quartersValue = .25;
  double dimesValue = .10;
  double nicklesValue = .05;
  double penniesValue = .01;
  double dollarsValue = 1;
  double quartersMoney;
  double dollarsMoney;
  double dimesMoney;
  double nicklesMoney;
  double penniesMoney;
  double totalMoney;
  double newTotalMoney;
  double oldTotalMoney = 0;
  int numberOfQuarters;
  int numberOfDimes;
  int numberOfNickles;
  int numberOfPennies;
  int numberOfDollars;



  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.piggybank);
    final EditText quarters = (EditText) findViewById(R.id.txtQuarters);
    final EditText dimes = (EditText) findViewById(R.id.txtDimes);
    final EditText nickles = (EditText) findViewById(R.id.txtNickles);
    final EditText pennies = (EditText) findViewById(R.id.txtPennies);
    final EditText dollars = (EditText) findViewById(R.id.txtDollars);
    Button calculate = (Button) findViewById(R.id.btnCalculate);
    final TextView results = ((TextView) findViewById(R.id.txtResults));
    final RadioButton add = (RadioButton) findViewById(R.id.radAdd);
    final RadioButton subtract = (RadioButton) findViewById(R.id.radSubtract);

    calculate.setOnClickListener(new OnClickListener()
    {

      public void onClick(View v)
      {
        if (quarters.getText().toString().equals(""))
        {
          numberOfQuarters = 0;
        }
        else
        {
          numberOfQuarters = Integer.parseInt(quarters.getText().toString());
        }

        if (dimes.getText().toString().equals(""))
        {
          numberOfDimes = 0;
        }
        else
        {
          numberOfDimes = Integer.parseInt(dimes.getText().toString());
        }

        if (nickles.getText().toString().equals(""))
        {
          numberOfNickles = 0;
        }
        else
        {
          numberOfNickles = Integer.parseInt(nickles.getText().toString());
        }

        if (pennies.getText().toString().equals(""))
        {
          numberOfPennies = 0;
        }
        else
        {
          numberOfPennies = Integer.parseInt(pennies.getText().toString());
        }

        if (dollars.getText().toString().equals(""))
        {
          numberOfDollars = 0;
        }
        else
        {
          numberOfDollars = Integer.parseInt(dollars.getText().toString());
        }
        quartersMoney = numberOfQuarters * quartersValue;
        dimesMoney = numberOfDimes * dimesValue;
        nicklesMoney = numberOfNickles * nicklesValue;
        penniesMoney = numberOfPennies * penniesValue;
        dollarsMoney = numberOfDollars;
        totalMoney = quartersMoney + dimesMoney + nicklesMoney + penniesMoney + dollarsMoney;
        DecimalFormat currency = new DecimalFormat("$###,###.##");

        if (add.isChecked())
        {
          if (totalMoney > 0)
          {
            newTotalMoney = oldTotalMoney + totalMoney;
            oldTotalMoney = newTotalMoney;
            results.setText(currency.format(newTotalMoney));
          }
          else
          {
            Toast.makeText(Piggy.this, "You need to do more chores!!", Toast.LENGTH_LONG).show();

          }
        }
        if (subtract.isChecked())
        {
          newTotalMoney = oldTotalMoney - totalMoney;
        }
        if (newTotalMoney > 0)
        {

          oldTotalMoney = newTotalMoney;
          results.setText(currency.format(newTotalMoney));
        }
        else
        {
          Toast.makeText(Piggy.this, "Save more money kido!!", Toast.LENGTH_LONG).show();
        };
      }
    });
  }

}

I have searched for an answer but they all seem to be slightly different situations. Any ideas? Thanks. And like I said, this works fine if the TextView box is overlapping the quarters EditText box.

Edit 1 Here is the screen before the piggy bank

main.xml

<?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"
    >
    <ImageView
            android:id="@+id/ic_launcher_money"
            android:layout_width="100px"
            android:layout_height="100px"
            android:layout_marginLeft="4px"
            android:layout_marginRight="10px"
            android:layout_marginTop="2px"
            android:src="@drawable/ic_launcher_money"></ImageView>

    <TextView
        android:id="@+id/bankses"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/bankses"
        android:textSize="25sp">

    </TextView>
</LinearLayout>

Main.java

package net.finalexam;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Main extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        String[] banks ={"Piggy Bank","Adult Bank"};
        setListAdapter(new ArrayAdapter<String>(this,R.layout.main, R.id.bankses, banks));
    }
    protected void onListItemClick(ListView l, View v, int position, long id){
        switch(position){
        case 0:
            startActivity(new Intent(Main.this,Piggy.class));
            break;
        case 1:
            startActivity(new Intent(Main.this,Adultbank.class));
            break;
        }
    }

}
  • 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-06T05:47:21+00:00Added an answer on June 6, 2026 at 5:47 am

    Try cleaning your project on Eclipse. It often fixes that kind of problems.

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

Sidebar

Related Questions

I have had this problem for a long time now, I hope stackoverflow can
Looks like others have had this problem but I can't seem to find a
I have had this problem w/ two seperate WYSWYG editors in my rails application
I'm very confused and am hoping someone might have had this problem and be
Has anyone had this problem? My projects tend to have some long XML files
Ok I have this problem that I've never had before, it's really bugging me.
I have a problem with this script. At first I had the <div> s
(I have a problem that I illustrated in this question but had no correct
I have had a few problems getting this right, so I wanted to ask
I have had this problem for a while, still trying to work on a

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.