Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] i am trying to make rock paper scissors game in android , and there a error i can not solve , error is coming in java

Posted on November 11, 2022 By

Solution 1 :

The layout the has the id @+id/answer1 is not a RadioGroup it’s GravityRadioGroup
Does your class GravityRadioGroup extends RadioGroup?
if not, you can solve this by:

ImageView pc;
/*RadioGroup answer1; --> */ GravityRadioGroup answer1;
TextView result;
Button enter;

Solution 2 :

Chnage RadioGroup answer1; to GravityRadioGroup answer1;.

Problem :

I am making rock paper scissors app in android studio. I am getting the error in “answer1 = findViewById(R.id.answer1);”. I have used dependency for git for radiogroup.

//////////////////////////////////////////////////////////////////////////////////////////////
xml code

 <xyz.teamgravity.imageradiobutton.GravityRadioGroup
            android_id="@+id/answer1"
            android_layout_width="match_parent"
            android_layout_height="wrap_content"
            android_orientation="horizontal">

            <xyz.teamgravity.imageradiobutton.GravityImageRadioButton
                android_layout_width="0dp"
                android_layout_height="wrap_content"
                android_layout_weight="1"
                android_padding="20dp"
                app_girbImage="@drawable/rock"
                app_girbPressedTextColor="@color/white"
                app_girbText="rock"
                app_girbUnpressedTextColor="?attr/colorPrimary"
                android_clickable="true"/>


            <xyz.teamgravity.imageradiobutton.GravityImageRadioButton
                android_layout_width="0dp"
                android_layout_height="wrap_content"
                android_layout_weight="1"
                android_padding="20dp"
                app_girbImage="@drawable/paper"
                app_girbPressedTextColor="@color/white"
                app_girbText="paper"
                app_girbUnpressedTextColor="?attr/colorPrimary" />



            <xyz.teamgravity.imageradiobutton.GravityImageRadioButton
                android_layout_width="0dp"
                android_layout_height="wrap_content"
                android_layout_weight="1"
                android_padding="20dp"
                app_girbImage="@drawable/scissors"
                app_girbPressedTextColor="@color/white"
                app_girbText="scissors"
                app_girbUnpressedTextColor="?attr/colorPrimary" />

        </xyz.teamgravity.imageradiobutton.GravityRadioGroup>

////////////////////////////////////////////////////////////////////////////////////////java code

public class MainActivity extends AppCompatActivity {

ImageView pc;
RadioGroup answer1;
TextView result;
Button enter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    pc = findViewById(R.id.pc);
    result = findViewById(R.id.result);
    answer1 = findViewById(R.id.answer1);
    enter = findViewById(R.id.enter);




    enter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            roll();

            int answer = answer1.getCheckedRadioButtonId();
            RadioButton radiobutton1 = findViewById(answer);
            String radio = radiobutton1.getText().toString();
            result.setText(""+radio);

        }

        private  void roll(){

            int num = (int)(Math.random() * 3 + 1);

            int answer = answer1.getCheckedRadioButtonId();
            RadioButton radiobutton1 = findViewById(answer);
            String radio = radiobutton1.getText().toString();
            result.setText(""+radio);




        }


    });

}

}

///////////////////////////////////////////////////////////////////////////////error

Caused by: java.lang.ClassCastException: xyz.teamgravity.imageradiobutton.GravityRadioGroup cannot be cast to android.widget.RadioGroup
    at com.example.rockpapersizer.MainActivity.onCreate(MainActivity.java:28)
    at android.app.Activity.performCreate(Activity.java:7893)
    at android.app.Activity.performCreate(Activity.java:7880)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)

Comments

Comment posted by ssojitra62

solution not working

Comment posted by Abdallah A. Odeh

What is the error? did it change?

Comment posted by ssojitra62

its worked but now i am not able to take input of radio group . its showing error in “int answer = answer1.getCheckedRadioButtonId();”

READ  [FIXED] android - Google In-App Purchase are always refunded
Powered by Inline Related Posts
Android Tags:android, java, radio-button, radio-group

Post navigation

Previous Post: [FIXED] android – Overlapping items in RelativeLayout with ImageView and TextView
Next Post: [FIXED] android – Unable to instantiate application com.company.app.MainApplication: java.lang.ClassNotFoundException React Native Expo

Related Posts

[FIXED] android – trying to retrieve users data Android
[FIXED] Flutter strange behaviour of stack item on android Android
[FIXED] android – Load Embedded Resources as Images in MAUI Android
[FIXED] android – Expand card view height to height of contained exoplayer, crop only left and right sides of expoplayer Android
[FIXED] broadcastreceiver – Android check connectivity on low battery (power saver mode) Android
[FIXED] Am Getting this error: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageView cannot be cast to android.widget.TextView Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme