Reputation: 19
I know there are many questions about this problem but non have answered my problem.
Everytime i make a new android application project with an empty activity and layout. it shows an error in R.layout.activity_main
heres the code:
package com.something.some;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
note: All this code was generated automatically by eclipse for me.
this is activity_main.xml(also automatically generated by eclipse in layout folder):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
i tried to clean and build the project. Even creating a new project, nothing worked! and i didn't import the "android.R"
Upvotes: 0
Views: 85
Reputation: 393
In the projects do you have image files?In my case was due to invalid names in images.
Upvotes: 0
Reputation: 3350
Creating a new Android app in Eclipse myself I saw that apps look like they need to import the appcompat library now.
Right click the project, go to Properties, select Android and in the bottom right add the appcompat library.
You have to have imported the appcompat library as a project from your_sdk_directory/extras/android/support/v7/appcompat/ (See https://developer.android.com/tools/support-library/setup.html )
UPDATE: I also needed to delete the app-support-v4.jar from the libs directory of the new project.
Upvotes: 0
Reputation: 48
I've had this problem once and I solved this by adjusting the last xml files before getting the error. Try to check your xml files such that there is no warning or errors in them.
Upvotes: 2
Reputation: 1032
Try importing packagename.R You ca find the package name in the manifest file package="com.example.main" //example package name
In your code do:
import com.example.main.R;
Upvotes: 0