Home » Android » Android Applications » How to fix – error: package R does not exist

How to fix – error: package R does not exist

When I was compiling one of our previously written android application, I got following error,

error: package R does not exist

This is because, in our app’s MainActivity we were using a code as below,

btn = (Button) findViewById(R.id.btn);

Solution :

The right solution to this error is to import the Resources’s class i.e. R as,

import your_package_name.R;

For example, our application’s package name is “com.demoapp.clickbutton” so we have to import R class as,

import com.demoapp.clickbutton.R;

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment