Reputation: 1305
I am teaching myself how to write an android application in eclipse. I have the following content in R.Java
public static final class menu {
public static final int activity_marblez_main=0x7f060000;
}
However, in my main java file, I can't seem to "see" my objects in R.java.
package com.example.marblez;
import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MarblezMain extends Activity {
//Custom View for Marble View
private MarblezView mView;
//ID for the menu exit option
private final int ID_MENU_EXIT = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mView = new MarblezView(getApplicationContext(), this);
mView.setFocusable(true);
setContentView(R.layout.activity_marblez_main);
}
My problem is that when I write the line:
setContentView(R.layout.activity_marblez_main);
It still can't see activity_marblez_main. I have imported the R.Java file. I have deleted it and regenerated it, but it can't fine "activity_marblez_main". Why? The specific error is:
"activity_marble_main cannot be resolved or is not a field"
I also cannot, for that matter, read anything else from the R.java file such as strings or anything. Does anyone know what could be causing this error. I am tearing my hair out. I know computers don't lie, but I am seeing everything where it should be and it is just like the program just won't read it?
Upvotes: 1
Views: 879
Reputation: 75629
Remove this line
import android.R;
as you are importing platform's R file, not yours, which should be:
import com.example.marblez.R;
(but you also can have none, which is OK). You can re-generate imports in Eclipse by pressing CTRL-SHIFT-O (letter "o"). Just ensure you got no platform R imported.
Upvotes: 2
Reputation: 24181
First thing is : create the layout activity_marble_main
( if you didn't create it ) , if it is , it will be added automatically to your (auto generated
class R.java
).
Second thing ,when your layout is added to your R.java
, it will be inside a static class named layout
( in your case you have static class menu
)
after all this , delete the import of android.R
( if there is an import )
and then when trying to find your layout by its id , import your class R ( com.yourpackage.R
) .
Upvotes: 1
Reputation: 13129
Your R.java file is generated by the eclipse Android Development Tools, you should never need to use it.
When you import it though IS important it should be YOUR package name. So for me would be import com.jenxsol.application.R
You are currently importing the android.R which will only ever return android resources.
Upvotes: 1