I have a res/layout/main.xml
including these elements and others:
The 'clean' option worked for me.
In my case, the root cause is that the source code resides on a network share, and my workstation and fileserver were not synchronized correctly, and had drifted by 5 seconds. The timestamps on the files created by Eclipse are in the past (because they are assigned by the fileserver) w.r.t. the workstation's clock, causing Eclipse to resolve dependencies between generated and source files incorrectly. In this case, a 'clean' appears to work, because it forces a complete rebuild instead of an incremental build that depends on wrong timestamps.
Once I fixed the NTP settings on my workstation, the problem never occured again. Without proper NTP settings, it would happen every few hours, as the clocks drift fast.
I have the same problem because in my custom view I overrided constructor but invoked super contructor withot attrs paramete. That is copy paste)
My previous constructor version:
public TabsAndFilterRelativeLayout(Context context, AttributeSet attrs) {
super(context);
}
Now I have:
public TabsAndFilterRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);}
And that works!
Be sure that the setContentView(R.layout.main)
statement call before findViewById(...)
statement;
For me, the problem was solved when I added the res folder to the Source in Java Build Path in project Settings.
In my case the view was in the parent NOT in the view I was trying to call it in. So in the child view I had to call:
RelativeLayout relLayout = (RelativeLayout) this.getParent();
View view1 = relLayout.findViewById(R.id.id_relative_layout_search);
Seems there is a variety of reasons. I just used "Clean..." in Eclipse to solve a similar problem. (FindViewByID had worked before and for some reason started to return null.)