Unfotunately, app has stopped

Unfotunately, app has stopped

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. 
 

2 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

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:

view sourceprint?

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".

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui