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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:09:18+00:00 2026-06-16T18:09:18+00:00

I am making an app where when we click on add button it adds

  • 0

I am making an app where when we click on add button it adds 1 to the number and when we click subtract it subtracts the number.

I am doing everything right but dont know why its giving error while processing in Emulator.

Below is my source code :

XML Code

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/total"
    android:id="@+id/tvDisplay"
    android:textSize="20dp"
    android:layout_gravity="center"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp"
    />
    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/add"
    android:layout_gravity="center"
    android:textSize="20dp"
    android:id="@+id/bAdd"
    android:layout_marginTop="25dp"
    android:layout_marginBottom="2dp"
    />
    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/sub"
    android:layout_gravity="center"
    android:textSize="20dp"
    android:id="@+id/bSub"
    android:layout_marginTop="25dp"
    android:layout_marginBottom="25dp"
    />

    </LinearLayout>

Java Code

  package com.example.plus.minus;

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

  public class PlusMinus extends Activity {

int counter;
Button add , sub;
TextView display; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    counter = 0;
    add = (Button) findViewById(R.id.bAdd);
    sub = (Button) findViewById(R.id.bSub);
    display = (Button) findViewById(R.id.tvDisplay);

    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Adds 1 to the counter
            counter = counter + 1;
            display.setText(" Your total is :" + counter);
        }
    });

    sub.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Subtract 1 from counter
            counter = counter - 1;
            display.setText(" Your total is :" + counter);
        }
    });
}
}

Also please let me know how can I find runtime errors myself.
And also how to debug errors myself.
Thanks In Advance

  • 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-16T18:09:19+00:00Added an answer on June 16, 2026 at 6:09 pm

    It should be TextView instead of Button

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

Sidebar

Related Questions

I am making app about google documents. but I don't know How to save
i am making a app which takes photo on button click i have camera.java
I'm making an app on Android and when I add a button with Eclipse's
i'm making app that the main page include TableView but i want when i
Hi i am making an app in which I am allowing user to add
I'm making an app that when you press a button it give you a
I'm making a web app in Asp.Net using c# that lets you add items
Making a SMS App and it is going well so far, but ran into
I am making an app that the user could add many accounts and view
I am making an app which will allow the user to click a picture

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.