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

  • Home
  • SEARCH
  • 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 9059711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:02:39+00:00 2026-06-16T15:02:39+00:00

Okay so I’m making a simple rock, paper, scissors game for android. So far

  • 0

Okay so I’m making a simple rock, paper, scissors game for android.
So far I have the following:

package com.example.digitoolz;

import java.util.Random;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

public class GameActivity extends Activity {
    private int userChoice;
    private int compChoice;

    private int userScore = 0;
    private int compScore = 0;

    private Toast winnerToast;

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


        ImageButton rockbutton = (ImageButton)findViewById(R.id.rock_button);
        rockbutton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                userChoice = 0;         
                compChoiceSelector();
                winSelect();
            }
        });

        ImageButton paperbutton = (ImageButton)findViewById(R.id.paper_button);
        paperbutton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                userChoice = 1;         
                compChoiceSelector();
                winSelect();
            }
        });


        ImageButton scissorsbutton = (ImageButton)findViewById(R.id.scissors_button);
        scissorsbutton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                userChoice = 2;     
                compChoiceSelector();
                winSelect();
            }
        });
    }   

        public void compChoiceSelector(){
            Random ran = new Random();
            compChoice = ran.nextInt(0) + 3;
        }

        public void winSelect(){
            if(userChoice == compChoice){
                winnerToast.setText("It's a Draw!");
                }else if (userChoice == 0 && compChoice == 1){
                    winnerToast.setText("Paper beats Rock! You Lose!");
                    compScore++;
                }else if (userChoice == 0 && compChoice == 2){
                    winnerToast.setText("Rock beats Scissorcs! You Win!");
                    userScore++;
                }else if (userChoice == 1 && compChoice == 0){
                    winnerToast.setText("Paper beats Rock! You Win!");
                    userScore++;
                }else if (userChoice == 1 && compChoice == 2){
                    winnerToast.setText("Scissors beats paper! You Lose!");
                    compScore++;
                }else if (userChoice == 2 && compChoice == 0){
                    winnerToast.setText("Rock beats scissors! You Lose!");
                    compScore++;
                }else if (userChoice == 2 && compChoice == 1){
                    winnerToast.setText("Scissors beats paper... You Win.");
                    userScore++;
            }else{
                    winnerToast.setText("");
            }
        }
    }

Basically, when it come to pressing any of the 3 buttons(rock, paper or scissors). I get a popup saying “Unfortunately digitoolz has stopped working.

I have no idea why this is happening!?
Please can someone help me!

Thank you to all in advance! 🙂

12-21 01:02:19.711: D/AndroidRuntime(573): Shutting down VM
12-21 01:02:19.721: W/dalvikvm(573): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-21 01:02:19.782: E/AndroidRuntime(573): FATAL EXCEPTION: main
12-21 01:02:19.782: E/AndroidRuntime(573): java.lang.IllegalArgumentException
12-21 01:02:19.782: E/AndroidRuntime(573):  at java.util.Random.nextInt(Random.java:187)
12-21 01:02:19.782: E/AndroidRuntime(573):  at com.example.digitoolz.GameActivity.compChoiceSelector(GameActivity.java:59)
12-21 01:02:19.782: E/AndroidRuntime(573):  at com.example.digitoolz.GameActivity$2.onClick(GameActivity.java:40)
12-21 01:02:19.782: E/AndroidRuntime(573):  at android.view.View.performClick(View.java:3480)
12-21 01:02:19.782: E/AndroidRuntime(573):  at android.view.View$PerformClick.run(View.java:13983)
12-21 01:02:19.782: E/AndroidRuntime(573):  at android.os.Handler.handleCallback(Handler.java:605)
12-21 01:02:19.782: E/AndroidRuntime(573):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 01:02:19.782: E/AndroidRuntime(573):  at android.os.Looper.loop(Looper.java:137)
12-21 01:02:19.782: E/AndroidRuntime(573):  at android.app.ActivityThread.main(ActivityThread.java:4340)
12-21 01:02:19.782: E/AndroidRuntime(573):  at java.lang.reflect.Method.invokeNative(Native Method)
12-21 01:02:19.782: E/AndroidRuntime(573):  at java.lang.reflect.Method.invoke(Method.java:511)
12-21 01:02:19.782: E/AndroidRuntime(573):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-21 01:02:19.782: E/AndroidRuntime(573):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-21 01:02:19.782: E/AndroidRuntime(573):  at dalvik.system.NativeStart.main(Native Method)
12-21 01:07:20.110: I/Process(573): Sending signal. PID: 573 SIG: 9

new Logcat:

12-21 02:33:17.920: D/AndroidRuntime(11568): Shutting down VM
12-21 02:33:17.920: W/dalvikvm(11568): threadid=1: thread exiting with uncaught exception (group=0x40abca08)
12-21 02:33:17.930: E/AndroidRuntime(11568): FATAL EXCEPTION: main
12-21 02:33:17.930: E/AndroidRuntime(11568): java.lang.RuntimeException: This Toast was not created with Toast.makeText()
12-21 02:33:17.930: E/AndroidRuntime(11568):    at android.widget.Toast.setText(Toast.java:277)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at com.example.digitoolz.GameActivity.winSelect(GameActivity.java:65)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at com.example.digitoolz.GameActivity$2.onClick(GameActivity.java:42)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at android.view.View.performClick(View.java:3538)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at android.view.View$PerformClick.run(View.java:14319)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at android.os.Handler.handleCallback(Handler.java:608)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at android.os.Looper.loop(Looper.java:156)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at android.app.ActivityThread.main(ActivityThread.java:5045)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at java.lang.reflect.Method.invokeNative(Native Method)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at java.lang.reflect.Method.invoke(Method.java:511)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-21 02:33:17.930: E/AndroidRuntime(11568):    at dalvik.system.NativeStart.main(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-06-16T15:02:40+00:00Added an answer on June 16, 2026 at 3:02 pm

    Your first problem is that nextInt() needs a number above 0. Anything supplied to nextInt() that is <= 0 throws that IllegalArgumentException.

    Your other problem may be:
    You don’t seem to be instantiating your winnerToast. It is global, but your code never actually does winnerToast = new Toast(this); You should probably add this line of code in your onCreate() method to avoid a NullPointerException.

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

Sidebar

Related Questions

Okay so I have a wordpress site. for example wordpress.com On it I have
Okay this question is very simple: I have a facebook page, and a website.
Okay, I have the following create action #posts_controller, nested resource under discussions def create
Okay - I have a dilemma. So far my script converts page titles into
Okay, so, for example, let's say I have an abstract class called Vehicle. The
Okay here's my situation. I have a php file that contains a simple form
Okay, this should be really simple, but I have searched all over for the
Okay getting some weirdness. I have a simple URLLoader in AS3 that loads an
Okay the answer to this may be really simple but I have been searching
Okay, next PHPExcel question. I have an HTML form that users fill out and

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.