Component ID does not appear in Mainactivity

Asked

Viewed 465 times

0

The problem is this, I add a component in my Activitymain, a button for example, but when I go to do the findviewById(ID) of the component, it does not show his ID in Mainactivity, it was working normal before, but now I went to add a new button and no more his ID, It appears in Activitymain, I put a normal ID on it, but when doing findviewById, the ID does not appear. I’m having this problem for the second time, the first time I solved it, but I had to create another project, copy all the code for the other project and then it went back to normal and I was able to add the component, but I didn’t want to have to do it for the second time, I’d like to understand why this is happening.

2 answers

0

The most likely problem is that you are not set the ID attribute correctly or it is not in the R file.

First check if you are setting the component id attribute:

<Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/button" />


If yes build the project so that references are added in the R file

0

The problem was that Android Studio was not kind of updating the components I put, I continued the work in the code until one hour the android studio gave a little attention, so I decided to look for the component ID and it was there, in fact, the problem should not have been even the Android Studio itself, but rather with my laptop that was overloaded with several tabs on Chrome opened as well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.