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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:26:38+00:00 2026-06-07T21:26:38+00:00

What is the mistake in this code? When I ran the program, it says

  • 0

What is the mistake in this code? When I ran the program, it says “The application buttonProj (process com.example.buttonproj) has stopped unexpectedly. Please try again”
I just tried to create an Add and Subtract button and user can click on it to increase or decrease number i.

  package com.example.buttonproj;

 import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

 import android.view.View;
 import android.widget.Button;
   import android.widget.TextView;


 public class MainActivity extends Activity {

int counter;
Button add, sub;
TextView display;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    counter = 0;

   add = (Button) findViewById(R.id.bAdd);
   sub = (Button) findViewById(R.id.bSub);
   display = (TextView) findViewById(R.id.textView1);

   add.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
        counter +=1;
        display.setText(counter);
    }
});
   sub.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
        counter--;
        display.setText(counter);


    }
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, 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-07T21:26:39+00:00Added an answer on June 7, 2026 at 9:26 pm

    use

    display.setText(""+counter);
     //OR
    display.setText(String.valueOf(counter));
    

    instead of

    display.setText(counter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please let me know where I made a mistake in this code?
I can't see a clear mistake in this code. Instead of validating my fields,
I try this code but it's a mistake because i have a repetition of
I can not understand my mistake in this code, it will compile if I
i made iPad application, i want to fetch data from this url, http://ipad.idealake.com/stockquote.aspx?id=SBIN and
this code was working fine till this morning, can anyone spot my mistake? probably
Please check this code: http://jsfiddle.net/rkumarnirmal/Rq7b2/2/ What I'm doing is I'm showing some text. If
sorry about input mistakes, english its not my mother lang. I have this code
Maybe it is just a simple mistake but this thing is driving me crazy.
This seems very foolish mistake, I just did a git stash pop on a

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.