Eclipse + Android plug-in.
Modify sample code that runs correctly.
When creating a new object in the existing code, error:
newObj cannot be resolved or is not a field
The first “suggested fix” adds it to the R.java file. (I also see that the first original object is listed there with a value.)
However, after I save the file, the IDE displays:
R.java was modified manually! Reverting to generated version!
How do I add this new object to the code? Should I just fore a new R.java file?
Any help in the right direction is greatly appreciated?
Thank You.
You should never modify R.java manually. This is generated from the xml files in the sub-folders of res. You should look in the example that you’re following where the declaration of newObj exists. The error you’re getting that newObj cannot be resolved probably means it has not been declared. Post a link to the sample code you’re working with and it will be much clearer how to fix this.
EDIT
After looking at the code sample linked in the comments, you’re missing the XYPlot object being delcared in your res/layout/main_activity.xml file. To be able to use R.id.newObj to refer to a view in your activity layout, it must exist as a control in the layout. And the casting implies that this control should be of type XYPlot (fully qualified with namespace when used in xml layouts).
EDIT 2
In order to use the findViewById method to resolve a View object, it needs to be in the layout’s xml. If you want to insert it into your layout in code, you need some other way of instantiating the object.