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,

[bash] btn = (Button) findViewById(R.id.btn); [/bash]

Solution :

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

[bash] import your_package_name.R; [/bash]

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

[bash] import com.demoapp.clickbutton.R; [/bash]

Leave a Comment