R file for custom component not compiling - android

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.

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"

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.

Related

Xamarin Android Google Maps error in Fragment

I'm getting an error while displaying maps in a fragment, I've been searching for the solution and Tried several codes but nothing seems to work.
MainActivity.xml
StackTrace: {Android.Views.InflateException: Binary XML file line #1: Binary XML file line #2: Error inflating class fragment --->
Android.Views.InflateException: Binary XML file line #2: Error inflating class fragment --->
Java.Lang.RuntimeException: API key not found.
Check that
is in the element of AndroidManifest.xml
it says API Key not found, but i did declared it in manifest and validated it using http://yougapi.com/tools/google-api-key-checker.php
AndroidManifest.xml
activity_main.xml
PS: Im using android 9.0 physical device for debugging
Please make sure if you have install Xamarin.GooglePlayServices.Maps package from NuGet.
And you used Android 9.0 physical device, please make sure your device if have Google Play services
I test my demo in the Android 10.0 emulator, it worked as normal.
Here is my demo. You can test it.
https://github.com/851265601/XAndroidMap

Error inflating class ImageButton during runtime but Android Studio shows no errors and compiles flawlessly

Application crashes with the following exception:
android.view.InflateException: Binary XML file line #185: Binary XML file line #15: Error inflating class ImageButton
But Android Studio shows no layout errors, layout preview of the file that is responsible for the crash is properly rendered and the application can be compiled and run.
Crashing ImageButton:
<ImageButton
android:id="#+id/kasablok_pager_btn_left"
android:layout_width="74dp"
android:layout_height="match_parent"
android:background="#FFFFFF"
app:srcCompat="#drawable/ic_chevron_right_black_24dp"
android:rotation="180"
tools:ignore="ContentDescription" />
The source drawable exists and is click-through to the file. There are no errors or warnings in the preview window to indicate a possible problem.
vectorDrawables.useSupportLibrary = true is also properly set in my build.gradle file.
Answer: the ic_chevron_right_black_24dp.xml file was located in the specific res/drawable-v24 folder instead of the common res/drawable. This way the id was only available on API 24+. Moving the file into the latter folder did solve the problem. My phone ran Android M (API 23) and that's why it crashed. The ic_chevron_right_black_24dp id could not be found.
How did the file end up in the wrong directory without my knowledge?
I copied the ic_chevron_right_black_24dp.xml file over from another project. What I did was to paste the file into the drawable resource directory while viewing the project as Android (the top left dropdown that allows you to choose how to represent your project in the left navigation panel). Android studio somehow decided to put the file into the specific drawable-v24 instead of the general drawable folder.
Why didn't Android Studio show any errors and why was the preview properly inflated?
The layout preview was properly inflated because the preview and also the compileSdkVersion was set to android-P. This way the preview was rendered as if it was on android-P API, where the resource existed.
How to tackle InflateException in your application?
When you see an InflateException, this exception itself doesn't provide any usable information about your problem. It can be caused by a variety of different independent things. You must look deeper. InflateException is not the cause - it is the effect caused by something else.
In my case the whole stack trace looked like this:
android.view.InflateException: Binary XML file line #185: Binary XML file line #15: Error inflating class ImageButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2335)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1423)
.....
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
.....
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070070
at android.content.res.Resources.getValue(Resources.java:1364)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:328)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:58)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:78)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageButton(AppCompatViewInflater.java:201)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:121)
That's more usable. The trace shows that the InflateException was triggered by a Resources$NotFoundException and this was the real culprit.
I solved this error, move the file(Image) from /res/drawable-v24 to the general folder /res/drawable, this is folder for any versions, and handle it with app:src in the layout code XML.

Xamarin Toolbar Hamburger Menu Break

I'm getting an unhandled exception when I try to access the hamburger menu on my Android simulator. The exception is:
Unhandled Exception: Android.Views.InflateException: Binary XML file line #14: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.ImageView occurred
It was working until very recently, but reverting all my code changes today doesn't fix the problem. I don't think the problem is with my code.
I don't know what I did to cause this, but I was playing around with different Navigation types when the problem came up. Couldn't find relevant information about the error online.

Error with com.viewpagerindicator.CirclePageIndicator

It worked before, but now it throws:
android.view.InflateException: Binary XML file line #16: Binary XML
file line #17: Error inflating class
com.viewpagerindicator.CirclePageIndicator caused by:
java.lang.UnsupportedOperationException: Can't convert to dimension:
type=0x1d`
I've tried to set #color/color_primary values and '#ff00ff' color hex
values: the same issue.
As a workaround: I set all needed colors in runtime by calling
setFillColor(), setPageColor() and setStrokeColor() respectively.
Library version compile 'com.viewpagerindicator:library:2.4.1#aar'
Source https://github.com/JakeWharton/ViewPagerIndicator/issues/424
This happens when you update your gradle version, and this Lib isn't giving any support or having updates for more than 5 years...
Despite I tried many other alternatives to keep using it, the best solution was to change it for this one:
implementation 'com.github.splatte:ViewPagerIndicator:3.0.0'
More information here: https://stackoverflow.com/a/47785895/6706788
There are other options there (one telling to add "app:" on all attributes of this lib), feel free to try them too if you want, for me, the solution of the alternative lib (a branch) was the only one that worked.

In Xamarin error inflating class cardview

I have used smaple Code of Xamarin.Andoird.Support.v7.Cardview though i get an bellow error
Caused by: android.view.InflateException: Binary XML file line #1:
Error inflating class android.support.v7.widget.CardView
Remove Android Support Library v7 CardView component and add it again! Rebuild the project and it's done! you should not be getting this error now!
I tried the same and it worked.

Categories

Resources