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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:56:36+00:00 2026-05-30T20:56:36+00:00

Basically I have to make a maths game with easy/medium/hard difficulties. I used the

  • 0

Basically I have to make a maths game with easy/medium/hard difficulties. I used the switch statement to achieve this which calls a method that deals with what to do in each difficulty.

The problem is that I can’t get my head around what this method with the switch statement should return, if anything, and how should I call it in the onCreate method. Also I don’t know why, but the TextView in the getPuzzle method is giving me an error when I call the tv.setText method on it.

public class Game extends Activity {
    private static final String TAG = "Brain Training";

    public static final String KEY_DIFFICULTY = "com.coursework.braintrain.difficulty";
    public static final int DIFFICULTY_EASY = 0;
    public static final int DIFFICULTY_MEDIUM = 1;
    public static final int DIFFICULTY_HARD = 2;
    public static final int DIFFICULTY_GURU = 3;


    private int brain;




    @Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");

    int diff = getIntent().getIntExtra(KEY_DIFFICULTY, DIFFICULTY_EASY);
    setBrain(getPuzzle(diff));
    getBrain();


    setContentView(R.layout.gamelayout);


    final EditText edittext = (EditText) findViewById(R.id.USERentry);


    final Button button1 = (Button) findViewById(R.id.keypad_1);
    button1.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            // Perform action on clicks
            //String buttonText = (String) button.getText();
            edittext.setText(edittext.getText() + "1");
            //edittext.setText() = edittext.getText() + "1";
        }
    });
    //rest of the bottons...
}


public void Easy12(){
    int a = (int) Math.random();
    int b = (int) Math.random();
    final TextView tv = (TextView) findViewById(R.id.question_label);
    String aString = Integer.toString(a);
    String bString = Integer.toString(b);
    String display = aString + bString;
    tv.setText(display);

}

private int getPuzzle(int diff){

    //TODO: Continue last game
    switch(diff){
    case DIFFICULTY_HARD:

        break;
    case DIFFICULTY_MEDIUM:

        break;
    case DIFFICULTY_EASY:
        Easy12();
        break;
    default: Easy12();
    }
    //might require to return an array or something
    return diff;


}


public int getBrain() {
    return brain;
}


public void setBrain(int brain) {
    this.brain = brain;
}


}

Any advice would be appreciated.

EDIT: Here’s the xml file that goes along with it:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent" 
              android:orientation="vertical" >
    <TextView android:id="@+id/question_label"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hello" />
    <EditText
    android:id="@+id/USERentry"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:drawable/editbox_background"
    android:textColor="@color/user_txt_color"/>"
    <TableLayout
    android:id="@+id/keypad"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stretchColumns="*">
    <TableRow>
        <Button android:id="@+id/keypad_1"
            android:text="1">
        </Button>
        <Button android:id="@+id/keypad_2"
            android:text="2"
            android:onClick="">
        </Button>
        <Button android:id="@+id/keypad_3"
            android:text="3">
        </Button>
    </TableRow>
    <TableRow>
        <Button android:id="@+id/keypad_4"
            android:text="4">
        </Button>
        <Button android:id="@+id/keypad_5"
            android:text="5">
        </Button>
        <Button android:id="@+id/keypad_6"
            android:text="6">
        </Button>
    </TableRow>
    <TableRow>
       <Button android:id="@+id/keypad_7"
            android:text="7">
        </Button> 
        <Button android:id="@+id/keypad_8"
            android:text="8">
        </Button>
        <Button android:id="@+id/keypad_9"
            android:text="9">
        </Button>
    </TableRow>
    <TableRow>
        <Button android:id="@+id/keypad_0"
            android:text="0">
        </Button>
    </TableRow>
    <TableRow>
        <Button android:id="@+id/keypad_del"
            android:text="del">
        </Button>
        <Button android:id="@+id/keypad_minus"
            android:text="-">
        </Button>
        <Button android:id="@+id/keypad_hash"
            android:text="#">
        </Button>
    </TableRow>

</TableLayout>

</LinearLayout>
  • 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-30T20:56:38+00:00Added an answer on May 30, 2026 at 8:56 pm

    You are getting a null pointer exception in the Easy12() method. As suggested by Knossos, this looks likely to be caused by question_label not existing in your xml layout. Make sure your xml contains something that looks like this:

    <TextView android:id="@+id/question_label"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hello" />
    

    You can still change the text of a TextView at runtime with the setText() method, the android:text attribute is just an initial value.

    If you still can’t get it working or see the problem, post your xml layout as well. If this was the problem, you might want to consider reading http://developer.android.com/guide/topics/ui/declaring-layout.html to understand xml layouts and how to use them a bit more.

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

Sidebar

Related Questions

Basically I have this application which scans through all mp3's in a folder and
Sorry if the title doesn't make sense. Basically I have a series of strings
I basically have a page which shows a processing screen which has been flushed
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);
I basically have three tables, posts, images and postimages (this simply contains the ids
I have a class, the outline of which is basically listed below. import org.apache.commons.math.stat.Frequency;
Ok guys I basically have a class which takes in 3 strings through the
I'm trying to make an easy side scrolling game just to learn the ropes
Here is my dilemma... I basically have a script which by means of CURL
I have to make a tool for automated distribution of the Java code. Basically,

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.