Android Add Button OnClickListener, NullPointerExceptiion Exception Occurred at Runtime

  android, question

I am new to Android and have just learned it for a few days. Please give me your advice. I am using the latest version of ADT.
There is only one button in the newly-created Android project. When the OnClickListener event listener is added to the button and executed,
Hint:
threadid=1: thread exiting with uncaught exception (group=0x4209a898)
The reason is:
Caused by: java.lang.NullPointerException
The line pointing to the error is the sentence that adds the click event (the second line of code below), and the following is the code that adds the event

Button btn = (Button)findViewById(R.id.button1);
 btn.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View arg0) {
 
 bracket
 });

Note: The package has been checked without error. The same code has no problem after using the old environmental test given by the teacher. However, the old version of ADT can’t recognize my mobile phone, and it’s too slow to use a virtual machine. The teacher helped me check and said that the button in xml was not available (the first line of code), but I don’t quite understand how to write it in the new version, please comment. If there are any details that need to be added, I hope to put forward.

Alas, btn is empty. FindViewById () traverses the layout of the root View, that is, setContentView () inside, to see if the layout inside has the id button1
-dividing line ah-
If the subject is the root View loaded through LayoutInflater, you need to call view.findViewById ()