0
我認爲它是由於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);
}
}
添加try/catch塊替換
,看看會發生什麼:沒有錯誤=沒有辦法知道,除非它是真的很明顯 –
你得到一個錯誤信息? –
請發佈異常堆棧跟蹤 – Sweeper