- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Tags:
- Android* OS
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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".

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page