Masum
Masum

Reputation: 3

R is Red color at "setContentView(R.layout.activity_main)" in MainActivity.java

When I open My any Project in Android Studio The main problem is in setContentView(R.layout.activity_main). Here showing error of R. When I use Rebuild Project the Problem is solved, but when I Run the project the same problem is appeared in the run time.

Upvotes: 0

Views: 2098

Answers (1)

Veneet Reddy
Veneet Reddy

Reputation: 2927

Try the following:

  • I find that R class not found related issues are usually because of errors in the xml resources(layouts, drawables, etc). Fix them and then try running.
  • Sync gradle manually: cmd+shift+a and search for gradle sync. Fix any errors that may popup.
  • Invalidate caches and restart Android Studio.

Upvotes: 1

Related Questions