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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:23:05+00:00 2026-05-20T14:23:05+00:00

Hello I’m a college student studying Java. I’m working on a android application. It

  • 0

Hello I’m a college student studying Java. I’m working on a android application. It compiles and shows no error. However when it runs, there’s a unexpected close error.

enter image description here

enter image description here

Here’s my application. When you click on the calculate ws you purpose to change to this screen.

Here’s my code:

package com.warhammerdicerrolleralpha;


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.ImageView;
import android.widget.TextView;

public class myMain extends Activity 
{

    EditText enternumberofdice;

    final TextView textGenerateNumber = (TextView) findViewById(R.id.text4);

    private EditText text, text2, text3;

    private Button btutorial1;

    int number1 = Integer.parseInt(text.getText().toString());

    int number2 = Integer.parseInt(text2.getText().toString());

    ImageView i = new ImageView(this);
    {
        i.setAdjustViewBounds(true);
    }

    private int myFaceValue;

    int myNum;

    /**
     * Called when the activity is first created.
     * 
     * @return
     */
    @Override

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

    public void go() 
    {
        while (myNum > 0) 
        {

            // TODO Auto-generated method stub
            textGenerateNumber.setText(String.valueOf(enternumberofdice));

             --myNum;

            return;
        }
    }

    public int roll() 
    {
        int val = (int) (6 * Math.random() + 1); // Range 1-6
        setValue(val);
        return val;
    }

    {
        try 
        {
            myNum = Integer.parseInt(enternumberofdice.getText().toString());
        } 
            catch (NumberFormatException nfe) 
        {
            enternumberofdice.setText("Does not work");
        }
    }

    public int getValue() 
    {
        return myFaceValue;
    }

    public void setValue(int myFaceValue) 
    {
        this.myFaceValue = myFaceValue;

    }

    {
        switch (myFaceValue) 
        {
        case 5:
            i.setImageResource(R.drawable.dicefive);
            break;
        case 1:
            i.setImageResource(R.drawable.diceone);
            break;
        case 3:
            i.setImageResource(R.drawable.dicethree);
            break;
        case 2:
            i.setImageResource(R.drawable.dicetwo);
            break;
        case 4:
            i.setImageResource(R.drawable.dicefour);
            break;
        case 6:
            i.setImageResource(R.drawable.dicesix);
            break;
        default:
            i.setImageResource(R.drawable.error);
            break;
        }

        text = (EditText) findViewById(R.id.editText1);

        text2 =(EditText) findViewById(R.id.editText2);

        text3 = (EditText) findViewById(R.id.editText3);      

        btutorial1 = (Button) findViewById(R.id.button1);

        btutorial1.setOnClickListener((OnClickListener) this);

        Button buttonGenerate = (Button) findViewById(R.id.button1);

        enternumberofdice = (EditText) findViewById(R.id.enternumberofdice);

        Button buttonGenerate2 = (Button) findViewById(R.id.battlecalculate);

        buttonGenerate2.setOnClickListener(new OnClickListener()    
        {

            @Override
            public void onClick(View v) 
            {
                    setContentView(R.layout.main2);
            }

        });

        buttonGenerate.setOnClickListener(new OnClickListener()     
        {
            @Override
            public void onClick(View v) 
            {
                // TODO Auto-generated method stub
                go();

                roll();
            }

        });
    }

    public void onClick(View view) 
    {
        switch (view.getId()) 
        {
            case R.id.button1:

                if (number1 > number2) 
                {
                    text3.setText("Three and above");       
                    return;
                }

                else if (number1 < number2) 
                {
                    text3.setText("Five and above");        
                    return;
                }

                else if (number1 == number2) 
                {
                    text3.setText("Four and above");        
                    return;
                }

                else
                {
                    text3.setText("Not Working");       
                    return;
                }

        }
    }
}
  • 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-20T14:23:05+00:00Added an answer on May 20, 2026 at 2:23 pm

    Look at your stack trace, but I think it may be because of this block:

    private EditText text, text2, text3;
    
    private Button btutorial1;
    
    int number1 = Integer.parseInt(text.getText().toString());
    
    int number2 = Integer.parseInt(text2.getText().toString());
    

    It looks as though you are trying to parseInt over null values. You need to specify where text, text2, text3 are in your form using similar code to:

    TextView textGenerateNumber = (TextView) findViewById(R.id.text4);
    

    Hope that helps.

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

Sidebar

Related Questions

Hello , I am currently working on the student association's website. The student's association
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello I am compiling a program with make but I get the error of
Hello all you helpful folks @ stackoverflow! Best resources for Java GUI's? Looking at
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello there and Merry Christmas !!! I am new to WPF and I am
Hello we have an SQL server application running over a low bandwith connection. We
Hello! There is a controller and an action which receives one param through GET,
Hello every one. I'm faced with a weird problem. My application has a simple
Hello in my java class Toto, I have 3 static methods I would like

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.