Why arent my new resources added in the res/ sub-folders showing up in the R class?
I don't understand why Eclipse doesn't know how to resolve the color resources I've defined. Am I doing something wrong?
R.color.notepad_lines cannot be resolved MyNewTextView.java
I've had problems before too with eclipse being able to find images in my /res/drawable directory
/res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<res开发者_如何学Cources>
<color name="notepad_paper">#AAFFFF99</color>
<color name="notepad_lines">#FF0000FF</color>
<color name="notepad_margin">#90FF0000</color>
<color name="notepad_text">#AA0000FF</color>
</resources>
MyNewTextView.java
...
private Paint marginPaint;
private Paint linePaint;
private int paperColor;
private float margin;
private void init(){
//Get Reference to Resource Table
Resources myRes = getResources();
//Create paint brushes
marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
marginPaint.setColor(myRes.getColor(R.color.notepad_margin));
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(myRes.getColor(R.color.notepad_lines));
paperColor = myRes.getColor(R.color.notepad_paper);
margin = myRes.getDimension(R.dimen.notepad_margin);
}
...
Eclipse keeps saying it can't find any of the R.* resources =/
R.java
public final class R {
public static final class attr {
}
public static final class color {
public static final int notepad_lines=0x7f040001;
public static final int notepad_margin=0x7f040002;
public static final int notepad_paper=0x7f040000;
public static final int notepad_text=0x7f040003;
}
public static final class dimen {
public static final int notepad_margin=0x7f050000;
}
public static final class drawable {
public static final int ic_menu_add=0x7f020000;
public static final int ic_menu_cut=0x7f020001;
public static final int ic_menu_king=0x7f020002;
public static final int icon=0x7f020003;
}
...
I've had this problem too, unless I let Eclipse create the file, rather that drop the XML file in under res/ somewhere. But I just found a way around this: In the Project Explorer view, find the res/values directory and select refresh from the right click menu:
colors.xml now appears in the explorer, and the R.java now contains the R.color
class. Rebuild it you don't auto-rebuild.
Ensure you are not importing the provided android Resource class 'import android.R' but your own generated Resource class e.g. import .R
This may be a stupid suggestion but... Is MyNewTextView.java in the same package name as the R.java file? If not, then you need to add a reference to the package via an import statement.
Delete the R.java file in the gen folder...
精彩评论