views:

17251

answers:

3

In my Android application, I have two activity classes. I have a button on the first one and I want to show the second when it is clicked, but I get an error. Here are the classes:

public class FirstActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button orderButton = (Button)findViewById(R.id.order);

    orderButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View view) {
        Intent intent = new Intent(FirstActivity.this, OrderScreen.class);
        startActivity(intent);
      }

    });
  }
}

The second class that should show when the button is clicked, but never does:

public class OrderScreen extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.order);

    Button orderButton = (Button) findViewById(R.id.end);

    orderButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View view) {
        finish();
      }

    });
  }
}

How do I create a button that will show the second activity?

+5  A: 

The issue was the OrderScreen activity wasn't added to the AndroidManifest.xml. Once I added that as an application node, it worked properly.

Tai Squared
+21  A: 

Add this line to your AndroidManifest.xml:

<activity android:name=".OrderScreen" />
A: 

Thanks for ur reply.But I Have the same problem in different layout it will show the error.I specified The activity name in manifestfile also but still show runtime error.can any one solve this.

This is my coding.

public class LoginApplication extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

    TabHost tabs =  (TabHost) this.findViewById(R.id.my_tabhost);
    tabs.setup(); 

    TabHost.TabSpec spec1 = tabs.newTabSpec("First tab");
    spec1.setIndicator("Login");
    spec1.setContent(R.id.content1);
    tabs.addTab(spec1);
    Intent intent = new Intent(LoginApplication.this, Login.class);
    startActivity(intent);


    TabHost.TabSpec spec2 = tabs.newTabSpec("Second tab");
    spec2.setIndicator("Settings");
    spec2.setContent(R.id.content2);
    tabs.addTab(spec2);

    TabHost.TabSpec spec3 = tabs.newTabSpec("Third tab");
    spec3.setIndicator("Favourites");
    spec3.setContent(R.id.content3);
    tabs.addTab(spec3);

    tabs.setCurrentTabByTag("First tab");

} }

next activity:

public class Login extends Activity { private EditText userName; private EditText password; private Button login;

private Button reset;
private Button changePassword;
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    gotoLogin();
}
   private void gotoLogin()
   {
       setContentView(R.id.Login);
       userName = (EditText)findViewById(R.id.userName); 
       password= (EditText)findViewById(R.id.password);
       login= (Button)findViewById(R.id.Login);
       reset = (Button)findViewById(R.id.Reset);
       changePassword=(Button)findViewById(R.id.ChangePassWord);

       reset.setOnClickListener(new OnClickListener()
      {
           public void onClick(View view) 
           {
            reset();
           }
      }
      );

      login.setOnClickListener(new Button.OnClickListener() 
       { 
           public void onClick (View v)
       {
               detailsPage(); 
               }});


       changePassword.setOnClickListener(new Button.OnClickListener()
       { 
           public void onClick (View v)
           { 
               changePassword(); 
           }});

   }

private void detailsPage() {

} private void reset() { userName.setText(""); password.setText("") ; } private void changePassword() {

}

}

Lakshmanan