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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:29:44+00:00 2026-05-27T18:29:44+00:00

Currently, my linearlayout is set as GONE in my main.xml . I need to

  • 0

Currently, my linearlayout is set as GONE in my main.xml. I need to set the visibility of my linearlayout to visibile automatically once a radio button is checked. But having error force close. Is there anything wrong with my codes?

calc.java

public class calc extends Activity implements OnClickListener{

EditText et;
RadioButton yes;

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

    Button submit =(Button)findViewById(R.id.submit);
    submit.setOnClickListener(this);

    final View linear = (EditText)findViewById(R.id.linear);
    yes = (RadioButton)findViewById(R.id.option1);
    yes.setOnCheckedChangeListener(new OnCheckedChangeListener()
    {

        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {

            if(yes.isChecked())
                linear.setVisibility(View.VISIBLE);

        }
    });
}

public void onClick(View arg0) {


}

}

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"
>

<RadioGroup
android:id="@+id/radioG"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true">

<RadioButton 
android:checked="false"
android:id="@+id/option" 
android:text="No"/>

<RadioButton 
android:checked="false"
android:id="@+id/option1" 
android:text="Yes"/>

</RadioGroup>

<LinearLayout
android:id="@+id/linear"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/radioG"
android:visibility="gone">

<TextView  
android:id="@+id/edit"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:text="Please enter something: "
/>

<EditText  
android:id="@+id/edit"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="numeric digits please"
/>
</LinearLayout>

<Button  
android:id="@+id/submit"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/linear"
android:text="Submit"
/>   

ERROR Message

Unable to start activity ComponentInfo{calc.calc/calc.calc.calc}: java.lang.ClassCastException: android.widget.LinearLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
  • 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-27T18:29:44+00:00Added an answer on May 27, 2026 at 6:29 pm

    You are casting your LinearLayout into an EditText here:

    final View linear = (EditText)findViewById(R.id.linear);
    

    Remove the cast and it should work.

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

Sidebar

Related Questions

I've prepared custom component based on LinearLayout. Whole component is defined in XML. Currently
So im trying to animate when i set the visibility of a linearlayout with
Currently I know of only two ways to cache data (I use PHP but
I'm trying to set a margin to RadioButtons added programmatically to a RadioGroup, but
I've got a layout much like the one below. Currently when the back button
I have an ImageView that I set to center inside the LinearLayout of a
If I set my ImageView to be both clickable and focusable, it works, but
I currently have my application set up with a ListFragment on the left and
I am currently setting up 3 textviews that go into a LinearLayout(code below). However
Currently I have tried aligning my Linear Layout to the left and center but

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.