티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

이클립스는 가장 높은 점수를, 안드로이드 스튜디오의 경우는 페이지 하단의 가장 최근에 업데이트 된 솔루션을 참고하세요.

그럼 아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

R cannot be resolved - Android error

"R cannot be resolved" - 안드로이드 오류

 문제 내용 

I just downloaded and installed the new Android SDK. I wanted to create a simple application to test drive it.

저는 방금 새로운 Android SDK를 다운로드하고 설치했습니다. 이를 테스트하기 위해 간단한 애플리케이션을 만들고자 합니다.

 

The wizard created this code:

위자드가 이 코드를 생성했습니다:
package eu.mauriziopz.gps;

import android.app.Activity;
import android.os.Bundle;

public class ggps extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

 

but Eclipse gives me the error

하지만 이클립스에서 다음과 같은 오류가 발생합니다.

 

R cannot be resolved

R이(가) 해결되지 않았습니다.

 

on line

해당 라인
setContentView(R.layout.main);

 

Why?

왜 그럴까요?

 

PS: I do have an XML file named main.xml under res/layout/.

PS: res/layout/ 디렉터리 아래에 main.xml이라는 XML 파일이 있습니다.

 

 

 

 높은 점수를 받은 Solution 

After tracking down this problem as well, I found this note in the Android documentation:

이 문제를 추적한 결과, Android 문서에서 이와 관련된 노트를 발견했습니다.

 

http://source.android.com/source/using-eclipse.html

위 링크는 안드로이드 소스 코드를 Eclipse IDE에서 사용하는 방법에 대한 안내서입니다.

 

*Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially when you ask Eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.*

*참고: Eclipse는 종종 리소스를 사용하는 파일의 맨 위에 "import android.R" 문을 추가하려고합니다. 특히 Eclipse에게 import를 정리하거나 관리하도록 요청 할 때입니다. 이렇게 하면 빌드가 실패합니다. 이러한 잘못된 import 문을 찾아서 삭제하세요.*

 

While going through the Android sample tutorials, I would often use the

Ctrl

+

Shift

+

O

command to "Organize Imports" and generate any missing import statements. Sometimes this would generate the incorrect import statement which would hide the R.java class that is automatically generated when you build.

Android 샘플 튜토리얼을 진행하면서 Ctrl + Shift + O 명령을 사용하여 "import" 문을 정리하고 누락 된 import 문을 생성하는 경우가 종종 있습니다. 때로는 이러한 오작동으로 인해 빌드시 자동으로 생성되는 R.java 클래스가 숨겨집니다.

 

 

 

 가장 최근 달린 Solution 

There are several reasons of R can't be resolved.

R이 해결되지 않는 몇 가지 이유가 있습니다.

 

  1. Most of time this error occur for XML file fault. This error can be solved by Clean and rebuild your project, also you can restart your android studio.
  2. Sometime If you codeing some wrong thingin AndroidManifest, this error can be occur so Please check this.
  3. If your resources contain the same name or they have invalid characters, this error can be occur.
1. 대부분의 경우 이 오류는 XML 파일의 문제로 발생합니다. 이 오류는 프로젝트를 정리하고 다시 빌드하거나 Android 스튜디오를 다시 시작하여 해결할 수 있습니다.
2. 때로는 AndroidManifest에 잘못된 코드가 있는 경우이 오류가 발생할 수 있으므로 이를 확인하십시오.
3. 리소스 이름이 동일하거나 잘못된 문자를 포함하는 경우이 오류가 발생할 수 있습니다.

 

If you already check those and yet you are facing with same problem then go ahead:

만약 이미 그것들을 확인했지만 여전히 동일한 문제가 발생한다면 다음을 진행하세요:

 


 

This error can be occurs when Android Studio fails to generate the R.java file correctly, so you have to follow those steps:

이 오류는 Android Studio가 R.java 파일을 올바르게 생성하지 못할 때 발생할 수 있으므로 다음 단계를 따라야합니다.

 

Step 1: Safely delete the build folder from app directory.
Step 2: In Android Studio, File -> Invalidate Caches / Restart
Step 3: Build -> Clean Project Then Build -> Rebuild Project.

단계 1: 앱 디렉토리에서 build 폴더를 안전하게 삭제합니다.
단계 2: Android Studio에서 File -> Invalidate Caches / Restart
단계 3: Build -> Clean Project, 그리고 Build -> Rebuild Project를 실행합니다.

 

so build folder will be regenerated and hope so error is gone.

이렇게 하면 build 폴더가 재생성되며 오류가 해결될 것입니다.

 


If Error still found then maybe you have performed refactoring the package name previously. This case you can press ALT + ENTER together for import the R.

만약 오류가 여전히 발생한다면, 이전에 패키지 이름을 리팩토링한 적이 있는지 확인해보세요. 그 경우에는 R을 import하기 위해 ALT + ENTER 키를 동시에 누르시면 됩니다.

 

 

 

출처 : https://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error

반응형
댓글
공지사항
최근에 올라온 글