我创建了一个简单的 Android 库应用程序,其中只有 1 个包含 TextView 的活动。它工作正常,但是当我将其标记为库并在另一个应用程序中引用时,当我尝试使用 findViewById(R.id.welcome_textview) 获取文本视图时,它会给出错误。
它生成了 R.java,但在我引用该库的第二个应用程序中,它不包含 id 字段。以下是正在生成的两个 R.java 文件:-
图书馆申请
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.example.mylibrary;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int welcome_textview=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
其他应用程序中的相同文件
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.example.mylibrary;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
我哪里错了?
经过几个小时的尝试,终于找到了问题所在。在引用的项目中,有一个自动创建的 Layout 文件夹是空的。删除该文件夹解决了该问题。希望这对某人有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)