我正在开发我的应用程序,一切正常,直到我尝试在 java 中显示图像。
我运行了一次应用程序,运行正常,显示了图片。
之后它要求我导入一些库,我导入了它们。之后我的活动出现错误。
错误如:
Gradle: error: cannot find symbol variable activity_main
Gradle: error: cannot find symbol variable button1
Gradle: error: cannot find symbol variable button2
Gradle: error: cannot find symbol variable textView
Gradle: error: cannot find symbol variable secondActivity
在 MainActivity 中我导入了这些库:
import android.R;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
在第二个活动中:
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
有谁知道如何解决这一问题?
编辑:我删除了import android.R;
现在它可以正常工作了。
你不应该导入android.R
。这应该是自动生成和识别的。这个问题如果您遇到一些错误,其中包含许多有用的提示R
删除导入后。
如果出现这些错误,删除导入后的一些基本步骤:
- 清理你的构建,然后重建
- 确保 XML 文件中没有错误或拼写错误
- 确保您的资源名称包含
[a-z0-9.]
。由于某种原因不允许使用大写字母或符号。
- 执行 Gradle 同步(通过“工具”>“Android”>“将项目与 Gradle 文件同步”)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)