0

I have two custom components, one which I made quite recently, both in Android Studio. The earlier one worked. I followed the same procedure to make the new one but it throws runtime errors when I reach the activity screen during testing.

These are the exception messages, listed in order:

1. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sentient/com.mycompany.MyActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class <unknown>
2. Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class <unknown>
3. java.lang.reflect.InvocationTargetException
4. java.lang.NoClassDefFoundError: com.mycomponent.R$color

Error #4 shows the actual line itself that throws the error, it is part of the constructor of the component:

int color = res.getColor(R.color.progress_gray);

I checked the R file manually, and found the colors (progress_gray is defined in the colors.xml) to be present. I removed the line, and another line throws the error instead (which again depends on the R file to get information).

I have tried cleaning, changing build order in gradle, Make the component separately, and I still can't figure out where the mistake is. Any help is appreciated! Thanks.

1
  • Make sure you're not importing android.R but yourApp.R Mar 10, 2015 at 12:46

2 Answers 2

1

can you post the xml file of the custom view?

Check if you have added to your main layout of the custom view xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res-auto"

0

I got the solution. The applicationId in build.gradle and the package in the manifest were not matching. Once I changed it, it worked.

Strange though, I had thought that the reason the two were separated was so that they could be named differently. In any case, that was what got it working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.