I am trying to call LinearLayout by its id. When I am trying to do so I am getting NoSuchFieldError.
LinearLayout l1 = (LinearLayout)findViewById(R.id.content2);
setContentView(l1);
I am trying to call LinearLayout by its id. When I am trying to do so I am getting NoSuchFieldError.
LinearLayout l1 = (LinearLayout)findViewById(R.id.content2);
setContentView(l1);
The way you are using is not correct.
setContentView(R.layout.main) must set with any layout say main.xml for your case.
and now the main layout is having the LinearLayout with id content2.
Also if you want to use setContentView directly create a dynamic linear layout i.e not in xml.
Linearlayout l1 = new LinearLayout(this);
//Set Layout params and bla bla... as per your need..
now setContentView(l1);
You can find that id, if and only if you have given that id in the xml resource file which you are inflating. Without loading the xml resource file you cannot find the id. YOu can load the xml resource file using the setContentView(R.layout.main); in the Activity onCreate(). The code for finding id will be like LinearLayout l = findViewById(R.id.content);