這是我的動態添加按鈕的代碼。運行時拋出錯誤。任何想法? :)這是怎麼回事?它的投擲錯誤
DatabaseHandler db;
private RelativeLayout relativeLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
boolean userCounts = db.getUserExistance();
if(userCounts == false){
Button button= new Button(this);
button.setText("Add password");
relativeLayout.addView(button);
}
else if(userCounts == true){
Button button2 = new Button(this);
button2.setText("Change password");
relativeLayout.addView(button2);
}
}
錯誤日誌:
09-17 11:44:34.658: D/AndroidRuntime(655): Shutting down VM 09-17 11:44:34.658: W/dalvikvm(655): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-17 11:44:34.699: E/AndroidRuntime(655): FATAL EXCEPTION: main
09-17 11:44:34.699: E/AndroidRuntime(655): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.projects.myworldsafe/com.projects.myworldsafe.Settings}: java.lang.NullPointerException
09-17 11:44:34.699: E/AndroidRuntime(655): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
有問題:) – Lucifer
上傳錯誤日誌約張貼堆棧跟蹤什麼?我們的傳感器不幸正在度假。 –
09-17 11:44:34.658:D/AndroidRuntime(655):關閉VM 09-17 11:44:34.658:W/dalvikvm(655):threadid = 1:線程退出時未捕獲的異常(group = 0x40a13300 ) 09-17 11:44:34.699:E/AndroidRuntime(655):致命異常:主 09-17 11:44:34.699:E/AndroidRuntime(655):java.lang.RuntimeException:無法啓動活動ComponentInfo {com.projects.myworldsafe/com.projects.myworldsafe.Settings}:java.lang.NullPointerException 09-17 11:44:34.699:E/AndroidRuntime(655):\t at android.app.ActivityThread.performLaunchActivity(ActivityThread。 java:2059) –