简体   繁体   中英

Android layout ids not recognised

I'm trying to get Android studio to recognise IDs of various views etc. in my layout.xml file. When I was inputting the code in the xml, everything seemed OK, but when I revisited my code today, the ids in the layout file were in red saying "cannot resolve symbol."

When I tried to access the view (eg using "view.findViewById(R.id.splo)"), it says it cannot resolve the symbol (in this case "splo").

I'm not doing anything radical, for instance this is how I define splo in my layout xml:

        <TextView android:id="@+id/splo" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="" />

Doing some digging, I found that I don't have a res/values/id.xml file - and looking further I don't have anything below app/build/generated/source, so no R.java file either.

I've looked at some people's requests for help - one was very similar to mine ( "cannot resolve symbol R" in Android Studio ) but the solutions offered don't help.

I've done multiple invalidate cache and restart, with or without Build->clean project and nothing works, and the IDs are still not recognised. Can anyone help?

Well there might be potential errors in the package name when you are building your application.

Since you mentioned, you already tried rebuilding and cleaning the project, we won't waste time doing that again!


What I want you to do now is:

  1. Open your AndroidMainfest.xml file
  2. Scroll to the top and check is the package name is correct
  3. If its correct then go to the Activity definitions in the manifest and check:
    • If the package name in these lines [android:name=" YOUR_PACKAGE_NAME . YOUR_ACTIVITY_NAME "] is correctly assigned
    • If you see the above line is in this format [android:name=". YOUR_ACTIVITY_NAME ]" , then bring it in the above format by adding the package name before the dot .
    • Now clean and rebuild your project.

The problem should be solved and if not my request is that please Upload your AndroidManifest.xml file and your package information so that I can have a better look at the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM