Marty_01
Marty_01

Reputation: 213

Cannot resolve symbol 'R'

I get this compiler error: Cannot resolve symbol 'R'. I know this question may seem familiar but many other questions related to this problem said that the code could compile despite the error while mine doesn't, or that the problem could be solved by cleaning the project and/or restarting Android Studio (I use 0.8.6), while in my case that doesn't work. Import class solves the compiler error but causes my app to crash when I start the activity. The code of the .java containing the error is:

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



/**
 * Created by Me on 16-11-2014.
 */
public class TutorialOne extends Activity {

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

I have also read that this may be caused by an error in the layout. Therefore I also include the code of the layout, which shows no compiler errors and is a pure pre-made layout:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</LinearLayout>

Furthermore, Im following this tutorial: https://www.youtube.com/watch?v=AN5EFviJRR0&list=PLB03EA9545DD188C3&index=10 which uses an old version of Eclipse, can this be causing some kind of problem?

Thanks and sorry if this is still considered a duplicate post

--SOLVED--

Im just stupid and, when creating TutorialOne as class, I accidently created the class in the map java instead of com.something.something.

Upvotes: 1

Views: 1270

Answers (2)

Rishi Dua
Rishi Dua

Reputation: 2334

Check the generated build file R.java. Check the classes and package names.

There might be an issue with it. Rebuild the project from Project > Clean and then select the project you want to clean up. This will build your project and create a new bin folder and regenerate the R.java file.

Upvotes: 2

n4zg
n4zg

Reputation: 397

I had a similar issue with my Android Studio, the way i fixed mine was by changing the compileSdkVersion to the latest version my studio has. eg.

compileSdkVersion 21

buildToolsVersion '20.0.0'

Hope this helps someone.

Upvotes: 1

Related Questions