Android nosuchfielderror solution

Android nosuchfielderror solution

A few days ago, at the time of development, a library was moved to a new project. Then the library Activity was called in the main application module, and NoSuchFieldError: was found.

However, there is no problem viewing the code. The layout file exists and the ID is correct, and the R file is normal. Later, I found the answer on stackoverflow because the main application module and the layout file in the library have the same name. Change one of the names to run normally. Later, I wrote a small demo to reproduce the error and analyze the packaged APK:

Main module files

Library files

Finally, in the APK file generated by packaging, there is only one layout file with this name, which is the layout file of the main module:

In addition, the ID in the resources.arsc file in the APK file does not have the ID defined in the library

conclusion

The packaging mechanism of Android determines that there can be no layout file with the same name, so it can only avoid the duplicate name of files between modules

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>