我认为它归功于OnClickButtonListener。之前,当我点击按钮时,应用程序会崩溃,但现在我已经为按钮添加了一个目的,或者至少尝试过,它在启动时崩溃了。
public class TimeSelection extends AppCompatActivity
{
private static Button button_sbm;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_selection);
OnClickButtonListener();
}
public void OnClickButtonListener()
{
button_sbm = (Button)findViewById(android.R.id.button1);
button_sbm.setOnClickListener
(
new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent("amardhebardevelopments.myapplication.UnitedStates");
startActivity(intent);
}
}
);
}
@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_time_selection, 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 :(得分:1)
尝试替换
button_sbm = (Button)findViewById(android.R.id.button1);
与
button_sbm = (Button)findViewById(R.id.button1);