View added from github library dont work - android

I wont to use nice Floating Action Button to my project. I want to use some libraries from github.
I like this FAB: https://github.com/Clans/FloatingActionButton .
I added dependences to gradle.app file:
compile 'com.github.clans:fab:1.6.2'
But my application does not work and crash.
XML:
<com.github.clans.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/plus"
android:layout_gravity="bottom|right"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
app:fab_colorNormal="#DA4336"
app:fab_colorPressed="#E75043"
app:fab_colorRipple="#99FFFFFF"
app:fab_showShadow="true"
app:fab_shadowColor="#66000000"
app:fab_shadowRadius="4dp"
app:fab_shadowXOffset="1dp"
app:fab_shadowYOffset="3dp"
app:fab_size="normal"
/>
LogCat:
FATAL EXCEPTION: main
Process: com.poltavets.app.howtodraw, PID: 31836
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.poltavets.app.howtodraw/com.poltavets.app.howtodraw.view.HowTo}: android.view.InflateException: Binary XML file line #23: Error inflating class com.github.clans.fab.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2462)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
at android.app.ActivityThread.access$800(ActivityThread.java:167)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1419)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class com.github.clans.fab.FloatingActionButton
at android.view.LayoutInflater.createView(LayoutInflater.java:637)
Line 23 of xml is:
<com.github.clans.fab.FloatingActionButton
Java:
public class HowTo extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.howtodraw);
}
}
In ANDROID STUDIOS ITs works:
How i can fix it?

as per the library have you included line in your main parent layout ?
xmlns:fab="http://schemas.android.com/apk/res-auto"

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

com.android.support:design with androidX (1.0.2)

I want to use TextInputLayout inside my project, but I'm using androidX library
implementation "androidx.appcompat:appcompat:1.0.2"
/*this don't work*/
implementation "com.android.support:design:28.0.0"
This is the exception which I'm facing
android.view.InflateException: Binary XML file line #30: Binary XML file line #30: Error inflating class android.support.design.widget.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class android.support.design.widget.TextInputLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.TextInputLayout" on path: DexPathList[[zip file "/data/app/com.example
Error inflating class android.support.design.widget.TextInputLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class
This error thrown when the Java Virtual Machine (JVM) tries to load a particular class and the specified class cannot be found in the classpath.
You should use
com.google.android.material.textfield.TextInputLayout
DEMO
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
Then Clean-Rebuild-Run.

Categories

Resources