Komal Gupta
Komal Gupta

Reputation: 1702

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.

Upvotes: 98

Views: 50778

Answers (9)

Amin Pinjari
Amin Pinjari

Reputation: 2173

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.

Upvotes: 0

Dzemo31
Dzemo31

Reputation: 1

I had this issue when using viewBinding. Class name was SearchViewHolder and layout resourse name was search_view_holder. That caused confusion and crash.

Upvotes: -1

Mohit Singh
Mohit Singh

Reputation: 177

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>;
}

Upvotes: 0

Mannu saraswat
Mannu saraswat

Reputation: 1081

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

Upvotes: 2

kundan kamal
kundan kamal

Reputation: 672

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.

Upvotes: 34

blastervla
blastervla

Reputation: 618

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.

Upvotes: 0

CoolMind
CoolMind

Reputation: 28835

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.

Upvotes: 2

user7176550
user7176550

Reputation: 1541

you have use multiple module and give same name of any xml layout then give this error so please rename your xml layout.

Upvotes: 8

JosephM
JosephM

Reputation: 2935

I think you have layout in both library and module with same name or inflating multiple xml layout with duplicate resource id.

Upvotes: 214

Related Questions