Software Archive
Read-only legacy content
17061 Discussions

Unfotunately, app has stopped

Farhan_I_
Beginner
420 Views

package com.example.qao;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class Main extends ActionBarActivity {
     int counter; 
     Button add, sub;
     TextView display;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        counter=0;
        add= (Button)findViewById(R.id.button1);
        sub= (Button)findViewById(R.id.button2);
        display=(TextView)findViewById(R.id.textView1);
        add.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                counter++;
                display.setText("Your Total Is "+ counter);
            }
        } );
        sub.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                counter--;
                display.setText("Your Total Is " +counter);
            }
        });
    } 

}

this is my program it shows no error on eclipse but when i run the program emulator doesn't run it emulator shows a message "unfortunately app has stopped" someone please find the mistake in it. I just started learning android development but now i am stuck with that problem. 
 

0 Kudos
1 Reply
Jorgesys
Beginner
420 Views

To solve this kind of problems is very important to post the messages displayed in LogCat, otherwise is very difficult to get a solution :(.

for my experience if you have the message: ""unfortunately app has stopped" the two main causes are:

1) any of this elements:

1 add= (Button)findViewById(R.id.button1);
2 sub= (Button)findViewById(R.id.button2);
3 display=(TextView)findViewById(R.id.textView1);

doesn´t exist inside the layout: "activity_main.xml"

2)  probably your activity is not registered inside the "AndroidManifest.xml".

0 Kudos
Reply