Can anyone help me to find out what can be the issue with this program.
In the onCreate()
method the findViewById()
returns null for all ids and th
Emphasis added
For those cases within an Activity class.
Activity.findViewById(int id)
Finds a view that was identified by the
id
attribute from the XML that was processed inonCreate(Bundle)
.
Otherwise, such as an Fragment, Adapter, a View
from a LayoutInflater
, etc.
View.findViewById(int id)
Look for a child view with the given
id
. If this view has the given id, return this view.
Either case,
Returns
The view if found ornull
otherwise.
Now, re-check your XML files. Make sure you put the right value into setContentView
or inflater.inflate
.
In the case of an Activity, call findViewById
after setContentView
.
Then, make sure there is a View you are looking for with android:id="@+id/..."
in that layout. Make sure the +
is at @+id
, which will add the resource to the R.id
values to ensure you can find it from Java.