Cannot find R.layout.activity_main

后端 未结 29 2168
轮回少年
轮回少年 2020-12-01 01:58

I was trying to work out with multiple layout using some online tutorials. The thing is my program was building and compiling correctly as long as there was only one XML fil

相关标签:
29条回答
  • 2020-12-01 02:30

    what I tried:

    1. check every XML file for some famous known errors.
    2. cleaned the project multiple times.
    3. synced Gradle with the project file.

    What Worked:

    1. Invalidate caches and restart.

    0 讨论(0)
  • 2020-12-01 02:30

    The stupid mistake I made to cause this error was to have the wrong package string in my AndroidManifest.xml file. I'd left the string set in the tutorial, but had used my own when setting up the project.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="COM.YOU.YOURAPPNAME"
    android:versionCode="1"
    android:versionName="1.0" >
    
    0 讨论(0)
  • 2020-12-01 02:31

    This is happening due to resources are not loading properly and the similar issue can occur any view also so Below are some technics which you can use to remove this error:-

    • Clean your project, Build -> clean Project
    • Rebuild project, Build -> Rebuild Project
    • Open manifest and check if there's any resource missing
    • Check-in layout to particular id if missing add it
    • If the above steps did not work then restart android studio with invalidating the cache.

    Note: In the above-mentioned steps, the last step will work for this issue for sure.

    0 讨论(0)
  • 2020-12-01 02:31

    There is probably an issue with the layout files, correct it and the auto generated class will appear.

    0 讨论(0)
  • 2020-12-01 02:34

    Check if you not imported android.R accidentally.

    0 讨论(0)
  • 2020-12-01 02:34

    I had a similar problem.
    It happened suddenly, after deleting some pictures from res. drawable. I did two things.

    • First I checked all my images in the drawable folder,if they all have preview. one of mine was damaged.
    • Secondly, I closed all opened android studio and emulator. After that every things worked fine.
    0 讨论(0)
提交回复
热议问题