我已经在这几个小时了,无法弄清楚。当我调试时,它给出了上述错误。我是新手,所以如果很明显我错过了什么,请保持温和...
这是从第一个活动中引入崩溃的代码,它仍然标记为“主要”:
//-- Menu Press --
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//-- Handle item selection
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent menu = new Intent(this, Menu.class);
menu.putExtra("plWin", plWin);
menu.putExtra("plLoss", plLoss);
menu.putExtra("plDraw", plDraw);
startActivity(menu);
return true;
case R.id.menu_reset:
if (opCounter > plCounter) {
plLoss++;
}else if (opCounter < plCounter) {
plWin++;
}else {
plDraw++;
}
opCounter = 0;
plCounter = 0;
return true;
default:
return false;
}
}
第二个活动,当前名为“菜单”:
public class Menu extends Activity {
Intent menu = getIntent();
int wins = menu.getIntExtra("plWin", 0);
int losses = menu.getIntExtra("plLoss", 0);
int draws = menu.getIntExtra("plDraw", 0);
private TextView winNum = null;
private TextView lossNum = null;
private TextView drawNum = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//-- Win Counter --
LinearLayout winView = (LinearLayout) findViewById(R.id.plLeft);
winNum = (TextView) winView.findViewById(R.id.winNum);
winNum.setText("" + wins);
//-- loss Counter --
LinearLayout lossView = (LinearLayout) findViewById(R.id.plMid);
lossNum = (TextView) lossView.findViewById(R.id.lossNum);
lossNum.setText("" + losses);
//-- Draw Counter --
LinearLayout drawView = (LinearLayout) findViewById(R.id.plRight);
drawNum = (TextView) drawView.findViewById(R.id.drawNum);
drawNum.setText("" + draws);
}
public void onBackPressed() {
finish();
super.onBackPressed();
}
}
这是我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sesto.life.counter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Main"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.sesto.life.counter.Menu"
android:label="@string/title_activity_menu" >
</activity>
</application>
我正在寻找想法。谢谢大家