DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Elevate Customer Engagement by Adding Google Play Instant to Your Android App
  • Getting Started With Android UI Development With Jetpack Compose
  • How it Feels to Switch from Eclipse to Android Studio
  • Overview of Android Networking Tools: Receiving, Sending, Inspecting, and Mock Servers

Trending

  • Zone-Free Angular: Unlocking High-Performance Change Detection With Signals and Modern Reactivity
  • Improving DAG Failure Detection in Airflow Using AI Techniques
  • The Third Culture: Blending Teams With Different Management Models
  • LLM Integration in Enterprise Applications: A Practical Guide
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. How to Rectify R Package Error in Android Studio

How to Rectify R Package Error in Android Studio

This tutorial demonstrates how to deal with common errors with your R package in the Android Studio, including error messages like R does not exist.

By 
George Martin user avatar
George Martin
·
Updated Feb. 17, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
75.2K Views

Join the DZone community and get the full member experience.

Join For Free

R.java plays a vital role in Android application advancement. It is utilized to distinguish all assets' information; for example, ID, format, picture, drawable assets, and so forth. R.java is produced by the Android Studio. In any case, it is at some point mistaken for a designer to utilize it. This article will assist you in resolving these issues you may be experiencing in R.java.

Where Is R.java Saved?

R.java is commonly saved in a directory like:

\Example\app\build\generated\source\r\debug\com\dev2qa\example\image.

You can also find it in an Android Studio project view list like below:

R.Java directory

Why Can I Not Find the R Class In the Android Studio?

This is a common dilemma because you select the wrong subview in the project view. You can change the project view’s subview, which is demonstrated below:

Click View —> ToolWindows —> Project in the top menu bar.

View - Tool Windows - Project

In the above action, it will show the project view in the left panel. At the top left in the project view, there is a drop-down list where you can choose the project view’s subview.

Drop down list

Choose the project on the subview drop-down list, then you can see all the folders for the current project listed in the bottom panel. You can find the R class in the directory tree also. If you choose another subview, it will display different content of that subview.

What Data Is Saved In R.java?

Double click R.java file. It will display its content in the right panel. The source code includes a lot of int-type variables, and each int variable refers to one resource in the current Android application.

You will find that there are some inner public static final classes defined in R.java also. Each inner class represents one kind of resource, such as ID, layout, string, color, drawable, etc.

Inner public static final classes

You do not need to care about those int variables and their values. Also, you do not need to edit them. If you change the value, you may encounter some strange errors when building the Android project.

How To Resolve the Package R Does Not Exist Error?

Sometimes, you may encounter strange errors about the R.class, like package R dost not exist or R cannot be resolved as a type. You can fix these errors by using the following steps:

R Does Not Exist Error

Click Build —> Clean Project or  Build —> Rebuild Project in the top menu bar of the Android Studio. This will let the Android Studio regenerate R.java again. It will clean the cache and include all newly added resources.

Build Rebuild Project

If the above method still does not take effect, you should check your AndroidManifest.xml file carefully. You need to make sure that the package value in the AndroidManifest.xml root XML element matches your activity package.

Matching package value

In the above picture, the manifest root XML element’s package value is com.dev2qa.example , and the launcher activity class is in the package com.dev2qa.example.image . So, if you change the package value, the error is resolved.

If the error still exists, you should check AndroidManifest.xml carefully to find the potential code that may generate the error. Or, you can restart the Android Studio or even your computer.

R (programming language) Android Studio Android (robot)

Opinions expressed by DZone contributors are their own.

Related

  • Elevate Customer Engagement by Adding Google Play Instant to Your Android App
  • Getting Started With Android UI Development With Jetpack Compose
  • How it Feels to Switch from Eclipse to Android Studio
  • Overview of Android Networking Tools: Receiving, Sending, Inspecting, and Mock Servers

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook