findViewById(int id) is a method of the View and Activity classes. This method will take a resource Id usually in the form of R.id.mView and will return to you a View object that is a reference to that View. Note that the returned object will nearly always need to be cast to the correct type of View before you can start interacting with it. If a View by the given ID does not exist within the current activity or parent View then you will receive null.
Questions tagged [findviewbyid]
563 questions
6
votes
1 answer
findViewById(int) returns null on one specific button in Android 3.1 other versions its fine
It's my first question but I'm trying to ask correctly.
As the title says only on one button and only in android 3.1 findViewById(int) returns null. Testing on Android 2.2 it works and all other buttons are found in both Android versions. It finds…

Martin
- 63
- 5
6
votes
4 answers
Can not find a View with findViewById()
I cannot find a TextView by calling findViewById(), even though the ID does exist.
OtherActivity:
public class OtherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
TextView textView =…

Zhe Xin
- 213
- 3
- 5
- 15
6
votes
0 answers
How much does the View Binding impact on the size of the app?
The View Binding, as specified by the documentation, generates a Binding class for each XML element, so as to facilitate access and inspection, as well as lighten the time load given by findViewById.
While the findViewById acts through a more…

Vincenzo Manto
- 886
- 1
- 11
- 30
6
votes
0 answers
kotlin - prevent lambda from capturing a view accessed using kotlin synthetics
I use the Kotlin Android Extensions plugin for accessing views from XML. If I understand that properly, the synthetic properties generated for the views are nullable, to be more precise - their type is View!, meaning that they can be treated as…

František Hlinka
- 100
- 7
6
votes
9 answers
When to call findViewById with menu item id to ensure it is not null?
I'm inflating the menu and trying to find the view of one of the menu items in the following way:
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
// will print `null`
…

Piotr Aleksander Chmielowski
- 5,640
- 7
- 29
- 45
6
votes
5 answers
( Toolbar ) findViewById( R.id.tool_bar ) return NULL
Yesterday I encountered a problem - findViewById( ) return NULL for my toolbar.
I was looking all around through the interner but it seems I can't find the solution for my "BIG" problem :D
Here's the styles.xml