Error inflating class TextView? - android

I am trying to display an AlertDialog but I am getting below error because of the TextView (code is given below). The dialog works fine when I comment out this TextView code.
Here's the TextView code,
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter OTP"
android:textSize="20dp"
android:padding="#dimen/min_padding"/>
Here's the Logcat error,
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class TextView
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 14 to dimension: type=0x4

Check the value of min_padding
You should create dimens.xml in the values folder .And min_padding has value .
Like this .
<resources>
<dimen name="min_padding">10dp</dimen>
</resources>

Id is missing in textView
I think you are not accessing valid id
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter OTP"
android:textSize="20dp"
android:id="#+id/textview"
android:padding="5dp"/>

Related

NullPointerException:Attempt toread from field 'androidx.viewpager2.widget.FakeDrag androidx.viewpager2.widget.ViewPager2.mFakeDragger' on null object

We are seeing this crash on Firebase for few of our users during layout inflation:
Fatal Exception: java.lang.RuntimeException: Unable to resume activity {com.abc.xyz/com.abc.xyz.onboarding.activity.OnboardingActivity}: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class <unknown>
Caused by java.lang.NullPointerException: Attempt to read from field 'androidx.viewpager2.widget.FakeDrag androidx.viewpager2.widget.ViewPager2.mFakeDragger' on a null object reference
at androidx.viewpager2.widget.ViewPager2.fakeDragBy(ViewPager2.java:735)
at androidx.viewpager2.widget.ViewPager2$PageAwareAccessibilityProvider.updatePageAccessibilityActions(ViewPager2.java:1494)
at androidx.viewpager2.widget.ViewPager2$PageAwareAccessibilityProvider.onSetOrientation(ViewPager2.java:1408)
at androidx.viewpager2.widget.ViewPager2.setOrientation(ViewPager2.java:569)
at androidx.viewpager2.widget.ViewPager2.setOrientation(ViewPager2.java:297)
at androidx.viewpager2.widget.ViewPager2.initialize(ViewPager2.java:190)
at androidx.viewpager2.widget.ViewPager2.<init>(ViewPager2.java:163)
at java.lang.reflect.Constructor.newInstance0(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:652)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:800)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:740)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:873)
We are not using FakeDrag ourself anywhere. Below is the XML code:
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/welcome_screen_vp2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-22dp"
app:layout_constraintTop_toBottomOf="#id/welcome_screen_hike_logo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
And in Kotlin file we are just attaching Viewpager2 to the TabLayout
TabLayoutMediator(mBinding.welcomeScreenVp2TabLayout, mPager) { tab, position ->
}.attach()
Any idea what could be the reason for this crash?

android studio keeps stopping - Android Studio [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm getting an Application Has Stopped Error.
I'm just starting out so I don't know much about this.
I looked at other threads but couldn't find anything similar to my code can you help me?
Process: com.example.andromeda, PID: 5300
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.andromeda/com.example.andromeda.MainActivity}: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class EditText
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class EditText
Caused by: java.lang.NumberFormatException: For input string: "AndroMeda"
at java.lang.Integer.parseInt(Integer.java:608)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:133)
at android.content.res.TypedArray.getInt(TypedArray.java:375)
at android.widget.TextView.<init>(TextView.java:1265)
at android.widget.EditText.<init>(EditText.java:88)
at android.widget.EditText.<init>(EditText.java:84)
at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:93)
when the application was run, it gave an error and these red texts appeared, I did not know what to do because I did not understand By the way This is my main activity.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/ad" />
<EditText
android:id="#+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/soyad"
android:inputType="#string/app_name"
android:text="#string/soyad" />
</LinearLayout>
I think these are the required files
Either remove android:inputType="#string/app_name" or set it to a valid value, such as text. AndroMeda (the apparent value of #string/app_name) is not a valid value for inputType.
replace android:inputType="#string/app_name"
with
android:inputType="text"

Fragment testing error: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class <unknown>

I am trying to test a fragment, following these instructions: https://developer.android.com/training/basics/fragments/testing
However I am getting the following crash when calling launchFragmentInContainer from my test.
Stacktrace:
android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createView(LayoutInflater.java:647)
...
at com.myapp.poll.PollHomeFragment.onCreateView(PollHomeFragment.kt:31)
...
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0301b1 a=-1}
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
at android.view.View.__constructor__(View.java:5010)
at android.view.View.<init>(View.java)
at android.widget.TextView.<init>(TextView.java)
...
at com.myapp.poll.PollHomeFragment.onCreateView(PollHomeFragment.kt:31)
Here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".poll.PollActivity">
<TextView
android:id="#+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="asdf#asdf.com" />
<TextView <!-- This is line 16 -->
android:id="#+id/tvViewPoll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:minHeight="48dp"
android:text="View Poll" />
<TextView
android:id="#+id/tvCreatePoll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:minHeight="48dp"
android:text="Create Poll" />
OK, from an educated guess based on the stacktrace, I tried removing android:background="?attr/selectableItemBackground" and this resolves the issue.
It appears that ?attr/selectableItemBackground is perhaps not compatible with FragmentScenario or this is a framework bug.
I submitted a bug on the issue tracker: https://issuetracker.google.com/issues/144629519
Update from Google:
Status: Won't Fix (Intended Behavior) The default theme does not have
an app defined attribute ?attr/selectableItemBackground (as Fragment
has no dependency on AppCompat, MDC, etc)
It sounds like you should be passing the correct theme to
FragmentScenario:
launchFragmentInContainer<PollHomeFragment>(themeResId = R.style.Theme_YourTheme)
In Java one also has to pass the theme to the FragmentScenario. Else the Fragment will not know about the current theme and will eventually complain that one should set an AppCompat theme ...
FragmentScenario<SomeFragment> scenario = FragmentScenario.launchInContainer(
SomeFragment.class,
Bundle.EMPTY,
R.style.Theme_Custom,
null
);
For me, using "android:?attr/selectableItemBackground" instead, solved the problem

java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewPager" on path

I just migrated my project to androidx and i am getting an inflation error for inflating viewpager component...I replaced android.support.v4.view.ViewPager with androidx.viewpager.widget.ViewPager
This my xml file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:padding="#dimen/_1dp"
android:layout_height="wrap_content"
android:background="#color/banner_border_color">
<androidx.viewpager.widget.ViewPager
android:id="#+id/vp_slider"
android:layout_width="match_parent"
android:layout_height="#dimen/_140dp"
android:background="#drawable/thumb_new_background" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<TextView
android:id="#+id/tv_banner_view_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/_16dp"
android:background="#drawable/drawable_btn_curved"
android:paddingBottom="#dimen/_6dp"
android:paddingLeft="#dimen/_8dp"
android:paddingRight="#dimen/_8dp"
android:paddingTop="#dimen/_6dp"
android:visibility="gone"
android:text="#string/text_view_more"
android:textColor="#color/c_white"
android:textSize="#dimen/_8sp" />
</RelativeLayout>
</FrameLayout>
The Error i'm getting :
Caused by: android.view.InflateException: Binary XML file line #329: Binary XML file line #8: Error inflating class androidx.core.view.ViewPager
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class androidx.core.view.ViewPager
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewPager" on path: DexPathList[
I figure out problem,
When we merger to androidx then android studio convert viewpager, swipe to refresh layout and some other views to androidx.core for example viewpager its looks like androidx.core.view.ViewPager but correct is androidx.viewpager.widget.ViewPager please check in your xml layouts and see there is right component is added or not if there is androidx.core then check for right one and replace it.
And also import dependency
implementation 'com.google.android.material:material:1.1.0-alpha08
You need to below dependencies in your build.gradle file
implementation 'com.google.android.material:material:1.1.0
You need to add below dependencies in your build.gradle file
implementation 'com.google.android.material:material:1.4.0
I think you need to Invalidate caches and restart
Go to File > Invalidate caches/Restart > ** Invalidate
Then rebuild project

How do i change custom view package name while that custom view xml file in the AAR file

i have aar file that contains drawable, layout and java file. One of xml file that contains Custom view and its class name is as per old project. so when i used in my new project then i get error of (i showed below)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.techreco.arcmenu.lib.AnimatedPathViewGroup" on path: DexPathList[[zip file "/data/app/com.example.pc28.arcmultiple-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.pc28.arcmultiple-2, /system/lib]]
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.techreco.arcmenu.lib.AnimatedPathViewGroup
so how do i solve this?
My current project package name: com.example.pc28.arcmultiple
and Custom view that is inside AAR file and its package name i cannot access. That custom view is
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<com.techreco.arcmenu.lib.AnimatedPathViewGroup
android:id="#+id/animated_path"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
/>
<com.techreco.arcmenu.lib.ArcLayout
android:id="#+id/item_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/> </merge>

Categories

Resources