我遇到了关于对SecondActivity的意图的问题,主要活动是具有进度条的启动画面。进度条间隔加载很好,当转到下一部分继续进行第二次活动时,我得到一些不可追溯且真正忙乱的错误。这是我的第二个活动的代码:
package com.example.waleedmalik.computerparts;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;
public class SecondActivity extends AppCompatActivity {
ToggleButton tb;
Button btn;
public static boolean tbflag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
tb = (ToggleButton)findViewById(R.id.toggleButton1);
btn = (Button)findViewById(android.R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
tbflag = tb.isChecked();
Intent in = new Intent(getApplicationContext(),
GameActivity.class);
startActivity(in);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:4)
按如下方式更改按钮初始化:
as
btn = (Button)findViewById(android.R.id.button1);
行到
btn = (Button)findViewById(R.id.button1);