0

I import an existing project into eclipse, and always encountered this problem. First, it appears the error: R cannot be solved. After import android.R. the error turned to the following methods. "start cannot be or is not a field"

I also checked the gen folder, where contains a R.java file. The file looks good, including the following contents: I also tried to clear the project and rebuilt which didnot work. Does any body have any idea how to solve this? Thanks a lot.

R.java:

public static final class layout {
   public static final int kbd=0x7f030000;
   public static final int main=0x7f030001;
   public static final int start=0x7f030002;
}

startactivity.java:

import android.R;
import android.R.layout;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;


public class StartActivity extends Activity {

    Intent mMain;

    /** Called when the activity is first created. */
    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start);//where error appears**
    }

    public void onStartButtonClick(View v) {
        mMain = new Intent(this, MainActivity.class);
        startActivity(mMain);
    }
B770
  • 1,272
  • 3
  • 17
  • 34
Foreverniu
  • 349
  • 1
  • 3
  • 18

3 Answers3

4

you are importing

android.R 

first remove android.R and android.R.layout from import and import R with your packagename.R

for eg. com.example.R instead of android.R

Michael Shrestha
  • 2,547
  • 19
  • 30
  • Thanks. I solved this problem by deleting all the import lines. And then use ctrl+shift+o to regenerate all the imports. – Foreverniu Jun 26 '13 at 17:25
1

Try doing Project -> Clean. If that doesn't work it looks like this might have already been answered: R cannot be resolved - Android error

Community
  • 1
  • 1
Padawan
  • 770
  • 1
  • 8
  • 18
  • Thanks, I tried to clean, but didnot work. The problem was solved by cleaning all imports and regenerate the imports. – Foreverniu Jun 26 '13 at 17:27
-1

To any one who may face the similar problem with me. I found an answer from the link below: R cannot be resolved - Android error

My problem was solved by: 1. delete all the imports lines. 2. press ctrl+shift+O to manually regenerate all imports.

And then the problem disappeared.

Many thanks for all the comments above.

Community
  • 1
  • 1
Foreverniu
  • 349
  • 1
  • 3
  • 18