R.java缺失,R不能解析到一个变量,即使在XML文件中没有错误缺失、变量、错误、文件

2023-09-05 04:54:58 作者:岁月蹉跎了容颜

我是新来的机器人,开始了我的编程基础。我收到错误的R不能解析为一个变量并R.java文件丢失,甚至我已经清除我的项目,并自动打造专业化了。请告诉我时间可能answer.And每次它显示了错误的R不能被解析为一个变量。为什么它正在发生。

I am new to android, started my programming basics. I am getting error as "R cannot be resolved to a variable" and R.java file is missing even i have cleaned my project and buid it automatically. Please tell me possible answer.And every time it shows the error that R cannot be resolved to a variable. Why it is happening.

我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

与code我的活动文件显示below.mainAvtivity文件:

My activity file with the code is shown below.mainAvtivity file:

package com.bis.databasedemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.R;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);       
}}

和我的清单文件在这里与下面的code。看看每code和给我的那个可​​能的答复尽快

and My Manifest file is here with the following code. look every code and give me possible reply for that as soon as possible:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bis.databasedemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.bis.databasedemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

请看看,并告诉我,之所以出现这样的错误是未来的没有任何过失的XML文件,而不是一次又一次的清洗,即使项目,并没有任何的SDK问题也在我日食那为什么还是同样的事情,R 1不能得到解决给一个变量。先谢谢了。

please have a look and tell me reason why such error is coming instead of not any mistake in xml file and even after cleaning project again and again and no any sdk issues also in my eclipse then why still same thing R cannot be resolved to a variable. Thanks in advance.

推荐答案

我发现这发生在我身上带着一个破碎的布局。没有必要担心。我想我最大的努力为您提供解决方案

I found this happening to me with a broken layout. No need to be worry. I am trying my best to giving you the solution

解决方案

请确保任何在研究。链接不破。修正XML文件中的所有错误。如果在ADKs什么都碎了,R将不会再生。

Make sure that anything the R. links to is not broken. Fix all errors in your XML files. If anything in the ADKs are broken, R will not regenerate.

如果你不小心碰到了什么东西,并在你的活动创建的进口android.R,将其删除。 运行项目 - >清除这将删除并重新生成R和BuildConfig

If you somehow hit something and created import android.R in your activity, remove it. Run Project -> Clean. This will delete and regenerate R and BuildConfig.

确认项目 - >建立自动被选中。如果不正确,通过人工建造它菜单 - >项目 - >生成项目

Make sure Project -> Build Automatically is ticked. If not, build it manually via Menu -> Project -> Build Project .

等待几秒钟消失的错误。

Wait a few seconds for the errors to disappear.

如果它不工作,删除里面的一切在 / GEN / 文件夹

If it doesn't work, delete everything inside the /gen/ folder

如果它仍然不能正常工作,请右键单击您的项目 - > Android的工具 - >修正项目属性

If it still doesn't work, try right-clicking your project -> Android Tools -> Fix Project Properties.

检查* .properties文件(在你的应用程序文件夹的根文件夹中),并确保在那里的联系不会中断。

Check your *.properties files (in the root folder of your app folder) and make sure that the links in there are not broken.

右键单击您的项目>属性> 机器人。

看项目建设目标和图书馆部分右侧的页面。您的构建目标应与目标在AndroidManifest.xml中。所以,如果它被设置为目标17 AndroidManifest,确保目标名称的是Android 4.2。如果你的图书馆有在基准的X,删除并重新添加库,直到有一个绿色的勾。如果你搬来搬去了一些文件和文件夹可能发生这种情况。

Look at the Project Build Target and Library sections on the right side of the page. Your Build Target should match the target in your AndroidManifest.xml. So if it's set to target 17 in AndroidManifest, make sure that the Target Name is Android 4.2. If your Library has an X under the reference, remove and re-add the library until there's a green tick. This might happen if you've moved a few files and folders around.

怎么做,如果R不再生

这通常是因为你有一个破损的XML文件。

This usually happens when you have a broken xml file.

检查错误,在你的XML文件,主要是在 / RES / 文件夹

Check errors inside your XML files, mainly within the /res/ folder

常见的地方是 /布局/ 和 /价值/ 特别是如果你最近改变其中的一个

Common places are /layout/ and /values/ especially if you've changed one of them recently

检查 AndroidManifest.xml中,我发现,我经常改变字符串,而忘记从AndroidManifest.xml中更改字符串名称。

Check AndroidManifest.xml, I find that often I change a string, and forget to change the string name from AndroidManifest.xml.

检查Android SDK中内建工具安装。 窗口 - > Android的SDK管理器 - >工具 - > Android SDK中内建工具

Check that Android SDK Build-tools is installed. Window->Android SDK Manager->Tools->Android SDK Build-tools

请确保当你更新了Android SDK工具,还更新了Android SDK平台,工具和Android ASK内置工具。建立静静地失败,如果他们不匹配。

Make sure when you update the Android SDK Tools, you also update the Android SDK Platform-tools and Android ASK Build-tools. Build fails silently if they don't match.

如果您不能找到问题,右键点击 / GEN / - >本地历史还原... - >勾R.java - >单击还原这并没有解决。的问题,但是它会清除掉多余的错误使问题更容易找到。

If you can't find the issue, right click /gen/ -> Restore from local history... -> tick R.java -> click Restore. This doesn't solve the problem, but it will clear out the extra errors to make the problem easier to find.

希望它会帮助你。 :)

Hope it will help you. :)