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.
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”.
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. I also tried restarting 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). 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.
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.