'NoSuchFieldError: No static field listView1 of type I in class Lcom/disdemo/R$id; or its superclasses
I have module1 (in Android Studio) with listView1 in activity_main.xml (present in res of the module1). The MainActivity of this module is being launched from another module2 in the same Android Studio project.
I have tried deleting the module1 and again creating a new one with same res and java files. Still I am getting the same issue.
Solution 1:[1]
I think you have layout in both library and module with same name or inflating multiple xml layout with duplicate resource id.
Solution 2:[2]
In both modules, you have an activity_main.xml. Please rename one file.
Update: What @kundan kamal wants to express is, you have a layout file in both modules with a similar name.
Solution 3:[3]
you have use multiple module and give same name of any xml layout then give this error so please rename your xml layout.
Solution 4:[4]
Make me correct If I am not wrong... I think you have the same name of your library and module in your project so you have to rename one of them then its work fine
Solution 5:[5]
In my case identifiers were different. I pressed Build > Rebuild Project. This is because I divided res/layout into subfolders, and AS stopped to notice XML changes. See Rebuild required after changing xml layout files in Android Studio for details.
Solution 6:[6]
This kind of error happened once to me, but with a string resource. I had the string configured in a translation file, but not in the default string resource file, so this produced the crash.
Solution 7:[7]
For me proguard rules worked. I had two level proguard. First in my dependency and then in my app. Had to do this in my dependency gradle.
Preserve R.. things.
-keepclassmembers class **.R$* {
public static <fields>;
}
Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
native <methods>;
}
Solution 8:[8]
Check if your xml is in same module/package/project where you have written the logic to show the code. In my case my xml was in different module which was not accessible.
Solution 9:[9]
I had this issue when using viewBinding. Class name was SearchViewHolder and layout resourse name was search_view_holder. That caused confusion and crash.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Dewsworld |
| Solution 3 | |
| Solution 4 | Mannu saraswat |
| Solution 5 | |
| Solution 6 | blastervla |
| Solution 7 | Mohit Singh |
| Solution 8 | Amin Pinjari |
| Solution 9 | Dzemo31 |
