Welcome to the Android Central Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 4 of 4
  1. Thread Author  Thread Author    #1  

    Default Application closing for no reason

    Hi guys i started learning android development about 2 days ago.. So was trying out with a basic application to increment and decrement.
    Everything is okay but when i'm testing the application even on the emulator, i get a message "Unfortunately, application <something written>"
    I tried debugging the code and found that Even after declaring a statement findViewById(), my variables are pointing to null. And i think that's the reason for this error.. heres my code, in MainActivity.java. Please help me out!

    Code:
    public class MainActivity extends ActionBarActivity {
    
        TextView sum;
        Button increment;
        Button decrement;
        int total;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            this.findViewById();
    
            total = 0;
    
            increment.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    total++;
                    sum.setText("Sum is "+total);
                }
            });
    
            decrement.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    total--;
                    sum.setText("Sum is "+total);
                }
            });
    
            if (savedInstanceState == null) {
                getSupportFragmentManager().beginTransaction()
                        .add(R.id.container, new PlaceholderFragment())
                        .commit();
            }
        }
    
        private void findViewById() {
            sum = (TextView) findViewById(R.id.tv);          // sum points to null
            increment = (Button) findViewById(R.id.inc);  //increment points to null
            decrement = (Button) findViewById(R.id.dec);  // decrement points to null
        }
  2. Thread Author  Thread Author    #2  

    Default Re: Application closing for no reason

    IS there no one who could help me out??
  3. #3  

    Default Re: Application closing for no reason

    thank you
  4. Thread Author  Thread Author    #4  

    Default Re: Application closing for no reason

    thank you?

Similar Threads

  1. What Phone to buy for LTE that works on Straight Talk?
    By robertp039 in forum General Help and How To
    Replies: 1
    Last Post: 03-08-2014, 08:04 PM

Posting Permissions