0

This is my first attempt at making an app, I was making the interfaces and got this error on all my activities activity_activityname cannot be resolved to a type. I have cleaned and rebuilt the project multiple times now and none of the solutions I have researched have helped.

package com.kev.runningdiary;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.R;
import android.R.layout; 


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

 }
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

remove the import android.R and android.R.layout(you want R to reference your own package not from android system)

after removing press Alt+Shift+O (or Cmd+Shift+O in OS X) (thats a quick shortcut to fix imports) when prompted which R class to include select the one from the local package

if that doesn't work (which probably means that your R class was deleted) try one of the fixes from this SO answers https://stackoverflow.com/a/8855902/616606

Community
  • 1
  • 1
Josh
  • 3,264
  • 1
  • 23
  • 35
  • I removed the R imports, Now there is an error with R. cannot be resolved to a variable. – user1048104 Apr 29 '13 at 20:56
  • 1
    If you are using Eclipse, Alt+Shift+O (or Cmd+Shift+O in OS X) will attempt to automatically add the correct imports for you - it should ask if you want to import the R class from the Android library or from your com.kev.runningdiary package - choose the latter. – Eric Brynsvold Apr 29 '13 at 21:06
  • thanks @EricBrynsvold i was trying to get eclipse up on my end so i can look up the shortcut – Josh Apr 29 '13 at 21:08
  • My R class isn't in the gen package, It deleted itself. From the research I have done, R will delete itself if resources aren't named in lower-case. But all my resources have lower case lettering. – user1048104 Apr 29 '13 at 21:10
  • @Josh, no problem, I use it all the time, so was able to come up with it off the top of my head...haha. – Eric Brynsvold Apr 29 '13 at 21:16
  • None of those suggestions worked unfortunately, I think I will just start the project again. Thanks for your help Josh and Eric. – user1048104 Apr 29 '13 at 21:26