3 Answers
3

If you get a NullPointerException when you switch from one layout file to another, it is most likely that you are accessing a reference to a View object with findViewById that doesn't exist in the new layout. findViewById is returning a null object, so the moment you call a method or access a public property of that object, you get the NPE.

You are trying to get a reference to the LinearLayout before it is created. You have to set the content view first and after that try to find the view by id. The other problem as that the id is wrong. Try this: