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

The Archive Base Latest Questions

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

Im pretty much a newbie at this so i could use some help to

  • 0

Im pretty much a newbie at this so i could use some help to know why does my app keep crashing ? I’ve tried a lot of ways and this is the best I’ve come so far.

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final TextView lastAnswer = (TextView) findViewById(R.id.textView5);
    final TextView answerLabel = (TextView) findViewById(R.id.textView1);
    final TextView answerLabel1 = (TextView) findViewById(R.id.textView2);
    final TextView answerLabel2 = (TextView) findViewById(R.id.textView3);
    final EditText enteredNumber = (EditText) findViewById(R.id.editText1);
    Button getAnswerButton = (Button) findViewById(R.id.button1);

    getAnswerButton.setOnClickListener(new View.OnClickListener() { 

            @Override   
        public void onClick(View arg0) {
                 Random randomGenerator = new Random();
                  //rand gene
                     int randomNumber2 = randomGenerator.nextInt(99);
                      int randomNumber = randomGenerator.nextInt(99);

            String number = "";
            String number2 = "";
            String jtext = " Times ";
            number2= Integer.toString(randomNumber2);
            number= Integer.toString(randomNumber);
            answerLabel.setText(jtext);
            answerLabel1.setText(number2);
            answerLabel2.setText(number);

            String content = enteredNumber.getText().toString();

When i comment the conditional the app works fine, but thats not all that i want
I suppose the problem is in the conditional but i can’t seem to find it.
no errors what so ever on eclipse.

            if (content != null){
                int anInt=Integer.parseInt(content);
                int result= randomNumber2 *randomNumber;

                    if(anInt == result ){

                      Context context =getApplicationContext();
                            CharSequence text = "That's correct!!";
                            int duration = Toast.LENGTH_SHORT;
                            Toast toast = Toast.makeText(context, text, duration);
                            toast.show();

                    } else{ 

                    Context context = getApplicationContext();
                    CharSequence text = "That's not correct";
                    int duration = Toast.LENGTH_SHORT;
                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show(); 
                    }
                    lastAnswer.setText(content);
            }

            }
        });}

So what im trying to do here (mind the noob code) is just generate 2 random numbers, display them and then have the user input the result, compare it, notify if right or not and then regenerate.. I’ve been working on this for days

any help is appreciated, even new ways of following this code. thanks.

  • 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-17T16:42:54+00:00Added an answer on June 17, 2026 at 4:42 pm

    You should probably surround your parsing with a try/catch. Users input being parsed back into a number might not always work – especially with EditTexts. Change

    int anInt=Integer.parseInt(content);
    

    So it is

      int anInt= -1;
      try{
       anInt = Integer.parseInt(content);
      }
      catch (NumberFormatException e)
      {
        //Show toast or dialog
      }
    

    Also to make life easier, you should make the EditText accept in only numbers.

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

Sidebar

Related Questions

Pretty much all the apps I use on a regular basis implement this 'seemly
I'm pretty much a newbie and I need to dig into this matter to
I am pretty newbie by this question. I want to know about possibilities of
I'm a total newbie when it comes to CSS so I've pretty much given
Pretty much the same as this question. But I can't seem to get this
Pretty much what it says on the tin. I've tried googling around but can't
this pretty much is the thing. When in tinymce I press anything that is
I am a pretty much a newbie to Entity Framework (specifically version 4) and
This should be pretty straight forward but I can't seem to get my newbie
Pretty much a newbie when it comes to both Django and Python. Would appreciate

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.