简体   繁体   中英

Starting new activity in the Android SDK

So I have this code in my main activity to start a new one:

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

        findViewById(R.id.GoButton).setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {                   
                Intent myIntent = new Intent(MainActivity.this, NewActivity.class);
                MainActivity.this.startActivity(myIntent);
                //finish();
            }
        });
    }
}

My new activity extends ListActivity and when I call this code by pressing the button it crashes the application. However if I make the MainActivity extend ListActivity then it works great (although I have to replace the button with a List!). Does anyone know why this happens, and how can I make it work using the code above?

Thanks

您是否添加了清单条目

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM