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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:26:26+00:00 2026-06-14T20:26:26+00:00

This is a simple app in android. It shows nullpointerexception while executing. I can’t

  • 0

This is a simple app in android. It shows nullpointerexception while executing.
I can’t get the value from the edittext. Here I just want to get the value from the edittext.
But it shows nullpointerexception..

how to solve this?

public class Calci extends Activity  {
    Button add;
    String str1;
    String str2;
    EditText txt1;
    EditText txt2;
    TextView tv;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calci);

        add=(Button) findViewById(R.id.button1);
        txt1=(EditText) findViewById(R.id.editText1);
        str1=txt1.getText().toString();
        txt2=(EditText) findViewById(R.id.editText2);
        str2=txt2.getText().toString();
        tv=(TextView) findViewById(R.id.textView4);

        addition();

        add.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                addition(); 
            }
        });
    }


    private void addition(){
        int res=0;
        res=Integer.parseInt(str1)+Integer.parseInt(str2);
        tv.setText(String.valueOf(res));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_calci, menu);
        return true;
    }
}
  • 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-14T20:26:27+00:00Added an answer on June 14, 2026 at 8:26 pm

    make sure you are setting default values for editText1 and editText2 in xml or if you want to access values enter by user then chnage your code as and remove addition() before setOnClickListener :

          //  addition();  comment this line 
            add.setOnClickListener(new View.OnClickListener() 
            {
    
                public void onClick(View v) 
                {
                      str1=txt1.getText().toString();
                      str2=txt2.getText().toString();
                      addition(); 
    
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a simple sip-based voip app for android. I used this sample
I have a simple app where you can login it looks like this: {{#view
I have a simple app that shows android notifications depending to one of three
I'm just trying to write a simple Android app that programatically shows whether the
I am writing a simple android app which have a edittext and a button.
hi working with simple android application that shows address of the user but this
I am writing my first simple Android App: It loads temperature samples from a
I'm following this tutorial: http://developer.android.com/training/basics/firstapp/running-app.html#Emulator In it there is a simple code for a
I am quite new in this. Now this simple app downloads image as a
So I wrote this simple console app to aid in my question asking. What

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.