Android Studio:Gradle:错误:找不到符号变量 [英] Android Studio: Gradle: error: cannot find symbol variable

查看:60
本文介绍了Android Studio:Gradle:错误:找不到符号变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发我的应用程序,一切正常,直到我尝试在 Java 中显示图像.

I was working on my app and everything was normal until I tried to display image in java.

我运行了一次应用程序,它运行正常,显示图片.之后它要求我导入一些库,我导入了它们.之后,我的活动出现错误.

I ran the app once and it ran normally, the picture was displayed. After that it asked me to import some libraries and I imported them. After that I got errors for my activities.

错误如:

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 中,我导入了这些库:

In MainActivity I have imported these libraries:

import android.R;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;

在 secondActivity 中:

and in secondActivity these:

import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

有人知道如何解决这个问题吗?

Does anyone know how to fix this?

我删除了 import android.R; 现在它可以正常工作了.

I deleted import android.R; and now it works normally.

推荐答案

您不应该导入 android.R.那应该是自动生成和识别的.这个问题包含很多有用的提示,如果你得到一些删除导入后引用 R 的错误.

You shouldn't be importing android.R. That should be automatically generated and recognized. This question contains a lot of helpful tips if you get some error referring to R after removing the import.

删除导入后的一些基本步骤,如果出现这些错误:

Some basic steps after removing the import, if those errors appear:

  • 清理你的构建,然后重建
  • 确保您的 XML 文件中没有错误或拼写错误
  • 确保您的资源名称包含 [a-z0-9.].出于某种原因,不允许使用大写字母或符号.
  • 执行 Gradle 同步(通过工具">Android">将项目与 Gradle 文件同步")
  • Clean your build, then rebuild
  • Make sure there are no errors or typos in your XML files
  • Make sure your resource names consist of [a-z0-9.]. Capitals or symbols are not allowed for some reason.
  • Perform a Gradle sync (via Tools > Android > Sync Project with Gradle Files)

这篇关于Android Studio:Gradle:错误:找不到符号变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆