-5

I have a program and when I try to start it, it crashes. I really don't understand why, even Eclipse show's that there are no errors. I can show you the code of a page on which I think is the problem.

 package ctect.android.maxipro;

 import android.os.Bundle; 
 import android.app.Activity; 
 import android.content.Intent; 
 import android.view.Menu; 
 import android.view.View; 
 import android.widget.Button;

 public class BasicScreenActivity extends Activity  { 
     private Button butonul1; 
     private Button butonul2;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_basic_screen);

         butonul1.setOnClickListener(new View.OnClickListener() {
                        @Override           
            public void onClick(View currentView) {
                      // TODO Auto-generated method stub        
              butonul2.setOnClickListener(new View.OnClickListener() {
                            @Override           
                public void onClick(View currentView) {
                          // TODO Auto-generated method stub
                        Intent myIntent = new Intent(currentView.getContext(), NeedForSpeedActivity.class);
                        startActivityForResult(myIntent, 0);
                        Intent myIntent2 = new Intent(currentView.getContext(), Fifa2012Activity.class);
                        startActivityForResult(myIntent2, 0); 
                    }   
                });             
            }       
         });
     }


     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
         getMenuInflater().inflate(R.menu.basic_screen, menu);
         return true;
     }
 }

if somebody understands, please help me.

4

1 回答 1

3

您忘记butonul1在使用之前将对象分配给它。您需要在之前添加此行butonul1.setOnClickListener

butonul1= (Button) findViewById(R.id.butonul1);

这是假设您butonul1在布局文件中为其提供了 id。

于 2013-08-21T20:38:24.923 回答