简体   繁体   English

为什么会发生这种R故障(Eclipse Android Java)?

[英]Why does this R glitch happen(Eclipse Android Java)?

This is a continuation off of Why is my layout unable to be resolved? 这是为什么布局无法解析的继续。 (Android/Java) (read the comments on the 1st answer) because I need to post a large amount of code, and doing that in a comment doesn't work. (Android / Java) (请阅读第一个答案的注释),因为我需要发布大量代码,并且在注释中执行此操作无效。

package scouting.form;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

public class Scouting extends Activity {

    CheckBox sground,strough,shigh,dground,dtrough,dhigh;
    Button logout,clr;
    EditText TeamNum;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scouting);
        TeamNum=(EditText) findViewById(R.id.TBTeamNum);
        sground=(CheckBox) findViewById(R.id.CBSGround);
        dground=(CheckBox) findViewById(R.id.CBDGround);
        strough=(CheckBox) findViewById(R.id.CBSTrough);
        dtrough=(CheckBox) findViewById(R.id.CBDTrough);
        shigh=(CheckBox) findViewById(R.id.CBSHigh);
        dhigh=(CheckBox) findViewById(R.id.CBDHigh);
        logout=(Button) findViewById(R.id.Logout);
        logout.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
        clr=(Button) findViewById(R.id.CLREntries);
        clr.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                sground.setActivated(false);
                strough.setActivated(false);
                shigh.setActivated(false);
                dground.setActivated(false);
                dtrough.setActivated(false);
                dhigh.setActivated(false);
            }
        });
    }
    @Override public void onBackPressed(){}
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_scouting, menu);
        return true;
    }
}

Every line with "R.xxx.xxx" says "R cannot be resolved as a variable". 每行带有“ R.xxx.xxx”的行均显示“ R无法解析为变量”。

I tried doing a clean, and since it's almost definitely a glitch in eclipse, I tried importing android.R, saving and cleaning, then un-importing android.R(importing android.R breaks everything dealing with it, but I did that intentionally), saving, and cleaning, to hopefully "refresh" it to make the glitch go away. 我尝试进行清理,由于它几乎绝对是日食中的小故障,所以我尝试导入android.R,保存和清理,然后取消导入android.R(导入android.R破坏了处理它的所有内容,但是我是故意这样做的),保存和清理,以希望“刷新”该错误以使其消失。 I also tried restarting Eclipse. 我还尝试重新启动Eclipse。 Still having this bug. 仍然有这个错误。

I fixed it! 我修好了它! So I had this file with the name "Gangam Style.mp3" in the raw folder(I have no clue how it got there). 因此,我在原始文件夹中有一个名为“ Gangam Style.mp3”的文件(我不知道它是如何到达的)。 I noticed an error saying that was an invalid name. 我注意到一个错误,说那是一个无效的名字。 I went into the folder and removed that file, and all of the errors went away. 我进入文件夹并删除了该文件,所有错误都消失了。 I guess having a bad file kind of messed with Eclipse and for whatever reason, it couldn't find R. 我猜有一个坏文件弄乱了Eclipse,无论出于什么原因,它都找不到R。

To anyone else who gets the error that R can't be resolved, make sure you aren't importing "android.R" and make sure you don't have any file with an invalid name in any of your folders. 对于其他收到无法解决R错误的人,请确保您未导入“ android.R”,并确保您的任何文件夹中都没有名称无效的文件。

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

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