简体   繁体   English

R.layout.main 无法解析

[英]R.layout.main couldn't be resolved

I am building an application and I added a new activity to generate a view.我正在构建一个应用程序,并添加了一个新活动来生成一个视图。 I compiled it.我编译了它。 My application can not find anything that is on the format R.id.xxx or R.layout.xxx , I've tried also cleaning my project, closing Eclipse and opening Eclipse again, but nothing.我的应用程序找不到任何格式为R.id.xxxR.layout.xxx ,我也尝试清理我的项目,关闭 Eclipse 并再次打开 Eclipse,但什么也没找到。 The most strange thing is that before everything was working well.最奇怪的是,之前一切都运转良好。 But now it can not recognize even the R.layout.main that is default of my principal activity.但是现在它甚至无法识别我的主要活动默认的R.layout.main Anyone have an idea?有人有想法吗?

Also I have tried almost everything here: R cannot be resolved - Android error but no result!此外,我在这里几乎尝试了所有方法: R 无法解析 - Android 错误但没有结果!

Solved解决了

Thanks to woopsy, also I found the reference to this kind of problem感谢 woopsy,我也找到了对此类问题的参考

http://source.android.com/source/using-eclipse.html http://source.android.com/source/using-eclipse.html

it happens because Eclipse sometimes imports R when you press the combination ctrl + shift + O发生这种情况是因为当您按下组合ctrl + shift + O时 Eclipse 有时会导入 R

Remove all your imports for the Activity and then have eclipse fix imports.删除 Activity 的所有导入,然后让 eclipse 修复导入。 I have had problems where eclipse wants to import a different R than the one I need.我遇到了 Eclipse 想要导入与我需要的 R 不同的 R 的问题。

First of All Check You have R.java File then check首先检查你有 R.java 文件然后检查

import android.R; 

Enter Yourpackages like import com.mypackages.prj;输入 Yourpackages,如import com.mypackages.prj;

this is a common error.这是一个常见的错误。 You need to just search your R.java file in generated section of your project directory in Eclipse.您只需要在 Eclipse 中项目目录的生成部分中搜索您的 R.java 文件。 Need to import if the R.java file into the package then import .如果需要将 R.java 文件导入包然后导入。 R; R; I hope it will work for you.我希望它对你有用。 It was absolutely worked for me...enjoy programming这对我来说绝对有用......享受编程

friends take care that u haven't imported R class, if you have delete " import android.R ".朋友注意你没有导入R类,如果你删除了“ import android.R ”。 The reason is there are two R things one R.java and R.class and we need the java, where we dont need to import rather than referring it.原因是有两个 R 东西,一个 R.java 和 R.class,我们需要 java,我们不需要导入而不是引用它。 It worked for me and may be to you too.它对我有用,也可能对你有用。

I found the solution...For me works it我找到了解决方案......对我来说有效

Poject->Properties->Android->Project Build Target (here choose android4.4 or 5.1.1 Android Open Source Project)->Ok Project->Build All Poject->Properties->Android->Project Build Target(这里选择android4.4或5.1.1 Android开源项目)->Ok Project->Build All

This function ...这个功能...

This problem can fix with this process: - File---->Invalidate cache/restart.此问题可以通过以下过程解决: - 文件----> 使缓存/重启无效。

it will restart your android studio and fix that problem它将重新启动您的 android studio 并解决该问题

If you are using eclipse, take a backup of your layout main.xml file and then from the eclipse new file interface create a new "Android XML File" and call it main.xml.如果您使用的是 eclipse,请备份您的布局 main.xml 文件,然后从 eclipse 新文件界面创建一个新的“Android XML 文件”并将其命名为 main.xml。 copy back from the backup the contents into this new file.从备份中将内容复制回这个新文件。

try this.试试这个。

check your xml files.检查您的 xml 文件。 there might be something wrong in it which is causing R not to build up automatically.它可能有问题,导致R不会自动建立。 To observe such errors, switch your view to Console tab要观察此类错误,请将视图切换到Console选项卡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM