In general, we will define some of the controls in the XML file to be used in the program, and the latest ADT will generate two XML files for each activity, one activity_main.xml and the other fragment_main.xml. At first I did not understand the difference between the two, in the fragment_main.xml definition of the control used in the activity, eclipse will not error. If you do not add some events for the control, such as clicking, the application will run normally. However, if you add event handling for the control, the runtime application crashes.
By looking at Logcat, the system prompts for a null pointer exception, but I can't find the code that caused the exception, only one line at a time, and finally found out that there was an error in looking for the ID of the control. But this ID I clearly defined and joined in the Fragment_main.xml. Later on the Internet to query the relevant knowledge, the Fragment_main.xml defined in the control all go to Activity_main.xml, the application will be working properly.
It is so visible that the control to be used in an activity must be defined in the corresponding activity.xml, so that it is convenient to add the control's event handling, cannot be defined in other XML files, otherwise the system will not error, but your application will crash. Hope to be like me just learn Android novice has certain help. And I don't understand why this is so? If there are seniors who know why, please comment to tell.