我有一个简单的应用程序,在主选项卡上,我有一个按钮。单击按钮时,假设启动另一个选项卡。但是,当我单击按钮时,屏幕变为空白,并显示:
不幸的是 appname 已停止
我哪里做错了?
代码片段包括:
MainActivity.Java
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void serveMenu(View view) { // Do something in response to button Intent intent = new Intent(this, ServeMenuActivity.class); startActivity(intent); } }
ServeMenuActivity.Java
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; public class ServeMenuActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_serve_menu); Intent intent = getIntent(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.serve_menu, menu); return true; } }
AdriodManifest.xml
<category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.mywinsystems.tkrctennistips.ServeMenuActivity" android:label="@string/title_activity_serve_menu" > </activity>