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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:39:48+00:00 2026-05-31T05:39:48+00:00

i displayed a expression on the screen 2+3=? and what i want to do

  • 0

i displayed a expression on the screen “2+3=?” and what i want to do is when i press 5 the question mark gets replaced by 5 and when i press # displays “correct” in green

package org.example.question;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class QuestionActivity extends Activity implements View.OnClickListener {
    /** Called when the activity is first created. */

    //variable for different questions

    //variable and type declaration for buttons and text

TextView display;
TextView displayGuess;
TextView displayQuestion;
TextView Correct;
TextView guess;
TextView question;


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

        //display text on screen
        displayGuess = (TextView) findViewById(R.id.Guess);
        displayQuestion = (TextView) findViewById(R.id.Question);


        //Creating and setting onClickerLIstener on each button
        Button one = (Button) findViewById(R.id.keypad_1);
        one.setOnClickListener(this);

        Button two = (Button) findViewById(R.id.keypad_2);
        two.setOnClickListener(this);

        Button three = (Button) findViewById(R.id.keypad_3);
        three.setOnClickListener(this);

        Button four = (Button) findViewById(R.id.keypad_4);
        four.setOnClickListener(this);

        Button five = (Button) findViewById(R.id.keypad_5);
        five.setOnClickListener(this);

        Button six = (Button) findViewById(R.id.keypad_6);
        six.setOnClickListener(this);

        Button seven = (Button) findViewById(R.id.keypad_7);
        seven.setOnClickListener(this);

        Button eight = (Button) findViewById(R.id.keypad_8);
        eight.setOnClickListener(this);

        Button nine = (Button) findViewById(R.id.keypad_9);
        nine.setOnClickListener(this);

        Button del = (Button) findViewById(R.id.keypad_delete);
        del.setOnClickListener(this);

        Button zero = (Button) findViewById(R.id.keypad_0);
        zero.setOnClickListener(this);

        Button hash = (Button) findViewById(R.id.keypad_hash);
        hash.setOnClickListener(this);

        Button minus = (Button) findViewById(R.id.keypad_minus);
        minus.setOnClickListener(this);

    }

        //method to tell what each button does
        public void onClick(View argh0) {



            switch(argh0.getId()) {

            case R.id.keypad_hash:

                if("2+3=5".equals(display.getText().toString()))
                {
                    display.setText("CORRECT".setColor."#00ff00");

                }
                break;

            case R.id.keypad_5:
                String str5 = display.getText().toString();
                display.setText(str5.replace("?","5"));
                break;






            case R.id.keypad_1:

                display.setText("1");
            break;
            }
        }
}

<?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/Guess"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text="Guess: "
        android:textSize="25dp" />
   <TextView
        android:id="@+id/Question"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text="2+3=?"
        android:textSize="25dp" />
   <TextView
        android:id="@+id/CORRECT"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text=""
        android:textSize="25dp" />
   <TextView
        android:id="@+id/INCORRECT"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text=""
        android:textSize="25dp" />









<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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" >
</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>

so far i can display the question but when i press “5” the application crashes

really will appreciate the help

  • 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-31T05:39:50+00:00Added an answer on May 31, 2026 at 5:39 am

    I don’t know whether you posted the whole code or not, but from what I see you never initialize the variable “display” (TextView display;). Then when you use it you will get a NullPointerException.

    I think you missed a line like display = (TextView) findViewById(R.id.display..);

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

Sidebar

Related Questions

I have a datagridview displayed on the screen. The user can change the end
hey i have displayed a pop-up screen when i click on a menu item
ALL COMPONENTS ARE DISPLAYED OK. BUT WHEN I PRESS F12 AND HOVER OVER NAVBAR-LEFT,
svn co https://src.springframework.org/svn/spring-samples/petclinic/trunk/ petclinic cd petclinic; mvn clean package The petclinic.war deploys just fine
i have created random expression and want to link their answers to the keypad
This is question about Objective-C. I wrote the program that uses regular expression with
I need to mask the password before it gets displayed in the log file.
I want to right-align the contents that are displayed in a vertically oriented StackPanel
I have descriptions being displayed within an XML document and then loading it into
This chart is displayed very nice but the log is not nice at all.

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.