FindViewById() not finding View

前端 未结 6 1729
青春惊慌失措
青春惊慌失措 2020-12-06 12:09

Just added a new button to my already-working-fine layout, but the findViewById function seems to be angry with something I don\'t get to understand.

Here\'s a bit o

相关标签:
6条回答
  • 2020-12-06 12:34
    import yourpackagename.R;
    

    instead of android.R;

    import R of your package

    Also Clean your project that will refresh your entire project then you will also find ID of button also

    0 讨论(0)
  • 2020-12-06 12:34

    Make sure to go through these processes.

    1: Make sure you imported your project R file.

    import packagename.R
    

    2: Clean your project

    3: If the above two solutions doesn't work, do invalidate your cache and restart

    0 讨论(0)
  • 2020-12-06 12:39
    1. Clean your project in Eclipse.
    2. Make sure the id is not duplicated
    3. Remove the button, save and add the button again and build the code.
    4. Make sure the correct R file is imported.

    If its a syntax related problem, then its got to do with compile time stuff.

    If its a problem when the code executes, make sure the layout is inflated. If the listview is found, then the button also must definitely be found.

    0 讨论(0)
  • 2020-12-06 12:45

    Some times the file R is not regenetated. Try :

    • Clean your project
    • Rebuild it
    • Manage to go back to a version that compiled and retry adding your elements one by one and compile each time to check the R file
    • Finnally the last option is to close/reopen eclipse yep some bugs can't be overcome other way ^^"

    No worry that's is just some common eclipse/android bug it happen often (Well some other times it can also be a small syntax error somewhere in your project but i assume that you already checked that x)

    Good luck

    0 讨论(0)
  • 2020-12-06 12:53

    while, just by clean you project, rebuild it, or import the R file manually, it might a sad thing to find the id of specified view component still cannot find by the activity. and then, if you check the detailed content of the R file, you will find the id has not generate, and then, what you need to check, if there are something wrong with your own /res file, for example, the name of the layout file, drawable file name, or the variant name of the menu file .etc. all of these could just make the R file cannot generate correctly, or even worse, the R file does not generate out at all.

    0 讨论(0)
  • 2020-12-06 12:56

    In Android Studio Build -> Clean Project resolved the problem for me.

    0 讨论(0)
提交回复
热议问题