When I was beginner at Android studio ,this was general issue I face through . Generally the problem arises when the R.java files during conversion of hex code properly donot recognize the appropriate magic number . So we should kept in mind that all the XML files are properly wriiten.This is oftenly arises due to problem in XML files . Go in each XML files n be sure all the files are true means valid . Then go to File and synchronize the project .My error remove many times by such steps .