Android: Out of memory Error on launch of Drawer layout - java

I am facing out of memory error when i debugged my code it is failing in below line of code:
setContentView(R.layout.activity_drawer);
The error is as below:
01-01 23:16:14.611 24083-24083/? E/CrashReporting﹕ ParseCrashReporting caught a OutOfMemoryError exception for wishlist.oj.app. Building report.
01-01 23:16:14.613 24083-24083/? E/CrashReporting﹕ Handling exception for crash
java.lang.OutOfMemoryError: Failed to allocate a 86400012 byte allocation with 16777120 free bytes and 66MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2578)
at android.content.res.Resources.loadDrawable(Resources.java:2471)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.widget.ImageView.<init>(ImageView.java:146)
at android.widget.ImageView.<init>(ImageView.java:135)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:58)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:54)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:95)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at wishlist.oj.app.home.ActivityDrawer.onCreate(ActivityDrawer.java:34)
at android.app.Activity.performCreate(Activity.java:6072)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424)
at android.app.ActivityThread.access$900(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:139)
My activity_drawer XML code looks like below:
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout"
tools:context=".ActivityDrawer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/tool_bar"
theme="#style/MyToolbarThemeSimple.Base"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/colorPrimary"
>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
</LinearLayout>
<!-- The Navigation drawer -->
<RelativeLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:background="#color/windowBackground"
android:id="#+id/drawer"
android:layout_gravity="start">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/cardview_drawer"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
I have tried many things like I increased the heap size to -Xmx2048m -XX:MaxPermSize=512m by using Compiler VM options.
Also, I checked the option "compile independent modules in parallel" present inside Settings => Build,Execution,Development Enviroment => compiler
But nothing worked out .. Any help??

A link showing how to load bitmaps efficiently with sample code.
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

This type of error usually occurs if your image is too large to be loaded (causing an OutOfMemoryError.
I would suggest scaling down your image, or using a lower resolution image, so it can be loaded into the memory easier.
There are also a variety of sources you can visit including the Android developer docs with a sample app, as well as YouTube videos such as this one.

Related

Android Notification add SeekBar

I currently generate a simple audio application. I would like to add a SeekBar panel to Android notification bar.
I learned from this writing, that RemoteViews does not supports SeekBar. I use NotificationCompat and RemoteViews for notification.
My code:
// add action to big remote view
// add action to small remote view
Notification notification = new NotificationCompat.Builder(WatchActivity.mActivity, ANDROID_CHANNEL_ID).
setCategory(Notification.EXTRA_MEDIA_SESSION).
setCustomBigContentView(mRemoteViewsBig).
setCustomContentView(mRemoteViewsSmall).
setContentIntent(contentIntent).
setOngoing(true).
setVisibility(NotificationCompat.VISIBILITY_PUBLIC).
setAutoCancel(true).
setOnlyAlertOnce(true).
setStyle(new NotificationCompat.DecoratedCustomViewStyle()).
setSmallIcon(R.mipmap.ic_launcher).
setSilent(true).
build();
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, notification);
startForeground(NOTIFICATION_ID, notification);
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_root"
android:layout_width="match_parent"
android:layout_height="120dp" >
<SeekBar
android:id="#+id/seekBarSoundProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/lblWidgetCurrentMusicName"
android:layout_alignStart="#+id/lblWidgetCurrentMusicName"
android:layout_marginTop="18dp"
android:max="100"
android:min="0"
android:progress="0" />
<!-- etc xml code -->
</LinearLayout>
</RelativeLayout>
Error (logcat):
2022-07-27 23:57:56.844 19485-19485/etc_package E/AndroidRuntime: FATAL EXCEPTION: main
Process: etc_package, PID: 19485
android.app.RemoteServiceException: Bad notification(tag=null, id=46) posted from package etc_package, crashing app(uid=11301, pid=19485): Couldn't inflate contentViewsandroid.widget.RemoteViews$ActionException: android.view.InflateException: Binary XML file line #44 in etc_package:layout/notification_big: Binary XML file line #44 in etc_package:layout/notification_big: Error inflating class huawei.android.widget.SeekBar
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2540)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8668)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
However, I have already seen some applications uses such feature:
Please kindly advice me how can I implement this feature?

Error inflating class android.fragment.app.FragmentContainerView, can someone tell me what I'm missing

I'm working on getting the Google Place API to appear within a CardView.
The particular code I'm looking at is from GitHub, seems to be working for everyone else but I don't understand why it's throwing me an error.
This is the error I am getting:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rizwanqureshi.kevstaxiscanterbury, PID: 6818
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rizwanqureshi.kevstaxiscanterbury/com.rizwanqureshi.kevstaxiscanterbury.CustomerMapsActivity}: android.view.InflateException: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Error inflating class android.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Error inflating class android.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #50 in com.rizwanqureshi.kevstaxiscanterbury:layout/activity_customer_maps: Error inflating class android.fragment.app.FragmentContainerView
Caused by: java.lang.ClassNotFoundException: android.fragment.app.FragmentContainerView
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.view.LayoutInflater.createView(LayoutInflater.java:815)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:438)
at android.app.Activity.setContentView(Activity.java:3324)
at com.rizwanqureshi.kevstaxiscanterbury.CustomerMapsActivity.onCreate(CustomerMapsActivity.java:116)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.fragment.app.FragmentContainerView" on path: DexPathList[[zip file "/data/app/com.rizwanqureshi.kevstaxiscanterbury-Nkg-1mQCfbE8I1MoJKHQuA==/base.apk"],nativeLibraryDirectories=[/data/app/com.rizwanqureshi.kevstaxiscanterbury-Nkg-1mQCfbE8I1MoJKHQuA==/lib/x86, /system/lib, /system/product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 32 more
The main takeaway is that there is an Error inflating class android.fragment.app.FragmentContainerView and that the issue is at line 50 of the XML.
This is the XML:
<FrameLayout
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"
tools:context=".CustomerLogin" >
<androidx.fragment.app.FragmentContainerView
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/buttons">
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/logout"
android:text="logout"
tools:ignore="ButtonStyle" />
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/history"
android:text="history"
tools:ignore="ButtonStyle" />
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/settings"
android:text="Settings"
tools:ignore="ButtonStyle" />
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_below="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20sp">
//***LINE 50 WHERE THE ERROR IS***
<android.fragment.app.FragmentContainerView
android:id="#+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ExtraText">
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
</android.fragment.app.FragmentContainerView>
</androidx.cardview.widget.CardView>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/driverInfo"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:background="#android:color/white"
android:visibility="gone">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="40sp">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:background="#android:color/white"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>
</FrameLayout>
So I guess there is something wrong with the FragmentContainerView? But i'm not getting any errors in the code and nothing is coming up on Google.
I feel like maybe something is outdated rather than outright incorrect but I haven't a clue.
Thanks for any input.
just try to define your startDestination in your navigation xml !
You should implement new androidx.fragment dependencies to use FragmentContainerView. It is already added since version 1.2.0. You can check here
implementation "androidx.fragment:fragment:1.2.5"
In my case, I had a Model which was used as arguments but I had not implemented Serializable and Parcelable implementaion.
This problem was created for me as well. The reason was two mistakes.
1.I did not add startDestination in nav graph .
2.I did not add #AndroidEntryPoint annotation in MainActivitey .
This error will only occur after you have added ProGuard & R8 to your project. To fix it, add the following two lines in proguard-rule.pro:
-keepnames class androidx.navigation.fragment.NavHostFragment
-keep class * extends androidx.fragment.app.Fragment{}
For me it was a typo within one of the fragments the navGraph, in the class path of the android:name attribute.. Adding a wrong path for the fragment class doesn't provide a compile time error, instead it raises android.view.InflateException...Error inflating class android.fragment.app.FragmentContainerView
So, make sure to have a correct packaging path for your fragments in android:name
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="#+id/nav_graph.xml"
app:startDestination="#id/mainFragment">
<fragment
android:id="#+id/mainFragment"
android:name="com.example.android....MainFragment" // <<<< This must be a correct path
android:label="main_fragment"
</fragment>
</navigation>
If it is Due to Proguard Then add few lines
In proguard-rules.pro file
....
# for FragmentContainerView error
-keepnames class androidx.navigation.fragment.NavHostFragment
-keep class * extends androidx.fragment.app.Fragment{}
Your activity must be a child of FragmentActivity to use androidx.fragment.app.FragmentContainerView either you extend the FragmentActivity or the AppCompatActivity which is a child FragmentActivity class. It is recommended to extend the AppCompatActivity.
see: https://www.tutorialguruji.com/android/trying-to-use-navhostfragment-and-im-getting-an-error-error-inflating-class-androidx-fragment-app-fragmentcontainerview/
Probably after Refactor->Remove unused resources you can lost id from your androidx.fragment.app.FragmentContainerView - bring it back
In my case, despite the same error, reason was different.
However this info about adding some rules to proguard-rules.pro pointed me into the right direction. This, and some other clues in error log about problems with argument in navigation XML file.
Eventually I found that it was problem with using my own classes in argument. And I don't mean the class of argument, but the fact that this class also used some of my other classes. And it was enough to add rules for each of these other classes:
-keepnames class <MyClass>
...
If you have done all the solutions and still the problem stands maybe you should check if your fragment constructor is empty.
In my case I looked deeper inside my stacktrace and found this line: Caused by: java.lang.IllegalStateException: FragmentContainerView must have an android:id to add Fragment MyFragment. Giving it an id and specifying tools:layout fixed problem

getLayoutParams() from LinearLayout return null

I want to implement a BottomSheetBehavoir component to an activity screen, but when I want to initialize the component via BottomSheetBehavoir.from(view) the getLayoutParams() method throw a null pointer exception.
This is my init code in onCreate():
LinearLayout llBottomSheet = findViewById(R.id.bottom_sheet_live_tracking_list_container);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(llBottomSheet);
And this is my xml layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_sheet_live_tracking_list_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
app:behavior_hideable="false"
app:behavior_peekHeight="40dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/rounded_corners_gray">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/show_more"
android:textColor="#color/white"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
android:id="#+id/activity_live_tracking_show_more_tv" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.1"
android:src="#drawable/ic_filter_list"
android:visibility="visible" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/activity_live_tracking_position_list_rv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
I include this layout in my root xml layout via the include tag.
Error code:
2020-02-21 12:34:05.097 8419-8419/de.app.haveltec.ilockit E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.app.haveltec.ilockit, PID: 8419
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.app.haveltec.ilockit/de.app.haveltec.ilockit.screens.livetracking.LiveTrackingActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6861)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
at com.google.android.material.bottomsheet.BottomSheetBehavior.from(BottomSheetBehavior.java:981)
at de.app.haveltec.ilockit.screens.livetracking.LiveTrackingActivity.onCreate(LiveTrackingActivity.java:147)
at android.app.Activity.performCreate(Activity.java:7232)
at android.app.Activity.performCreate(Activity.java:7221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2964)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:201) 
at android.app.ActivityThread.main(ActivityThread.java:6861) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
As mentioned in the documentation BottomSheetBehaviour is deprecated. If you still want to use it, make sure it is child of a CoordinatorLayout as that is a prerequisite to use it according to the doc.
Would rather have added this answer as a comment, but not enough reputation...
So after I rest some days and go back to the problem I found the solution. For my LinearLayout, that throws the getLayoutParams() null pointer exception, I use the id from the bottom sheet xml that you can see in my post android:id="#+id/bottom_sheet_live_tracking_list_container". In my main layout there the parent is a CoordinatorLayout is include my bottom sheet layout like this:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
... other stuff ....
<include
android:id="#+id/activity_live_tracking_bottom_sheet"
layout="#layout/bottom_sheet_live_tracking_list" />
Know I try the id from the include tag (android:id="#+id/activity_live_tracking_bottom_sheet") and it works. I can't give you an explanation why the other id that marked the LinearLayout directly returning null for getLayoutParams() method.

Binary XML file line #38: Error inflating class

I'm using 2 phones for debuging and 1 phone is showing my activity fine and the other dose the error, how can I repair it + how can I handle it for another users to not have crashes?
the crash:
07-19 19:51:33.614 18679-18679/itay.finci.org.allerwarn E/AndroidRuntime: FATAL EXCEPTION: main
Process: itay.finci.org.allerwarn, PID: 18679
java.lang.RuntimeException: Unable to start activity ComponentInfo{itay.finci.org.allerwarn/itay.finci.org.allerwarn.intro.IntroActivity}: android.view.InflateException: Binary XML file line #38: Error inflating class com.miz.introactivity.NextDoneButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #38: Error inflating class com.miz.introactivity.NextDoneButton
edit:
thanks for AndroidStudio decompiler I adding the done.xml that dose all the errors.
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="36dp"
android:viewportHeight="48"
android:viewportWidth="48">
<group android:name="done_group">
<path
android:name="done"
android:fillColor="#android:color/white"
android:pathData="M18 32.34L9.66 24l-2.83 2.83L18 38l24-24-2.83-2.83z" />
</group>
</vector>
edit 2:
the layout xml out of the library:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<FrameLayout
android:layout_width="match_parent"
android:paddingLeft="#dimen/title_padding_left"
android:paddingStart="#dimen/title_padding_left"
android:paddingRight="#dimen/title_padding_right"
android:paddingEnd="#dimen/title_padding_right"
android:layout_height="#dimen/navigation_height"
android:layout_gravity="bottom">
<Button
android:id="#+id/skip_button"
android:layout_gravity="center_vertical|left|start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/skip"
android:textColor="#color/skip_text_color"
style="?attr/borderlessButtonStyle"
/>
<LinearLayout
android:id="#+id/progress_layout"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.miz.introactivity.NextDoneButton
android:id="#+id/next_button"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center_vertical|right|end"
android:background="#drawable/next_done_button_selector"
/>
</FrameLayout>
</merge>
its an error in your IntroActivity. InflateException: Binary XML file line #38: Error inflating class com.miz.introactivity.NextDoneButton
More than likely; this could be due to any LARGE images you are using and the device is simply out of memory to display it. Try resizing the image to make the size of it smaller

Android Sliding Tabs crashes ( logcat: Can't convert to color: type=0x1 )

I am trying to make sliding tabs with icons. I have written the code using google's slidingtablayout.java and slidingtabstrip.java
The issue I am encountering is that my app is getting crashed in my phones (tested on kitkat and lollipop). However, I do not know why tablets are supporting the app and it runs flawlessly on my tablet (ICS), tablet emulator and bluestacks.
Logcat:
06-04 03:45:42.970 3254-3254/com.easyaccom.abhishek.slidingtabswiper E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.easyaccom.abhishek.slidingtabswiper, PID: 3254
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.easyaccom.abhishek.slidingtabswiper/com.easyaccom.abhishek.slidingtabswiper.MainActivity}: java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
at android.content.res.TypedArray.getColor(TypedArray.java:404)
at android.app.Activity.onApplyThemeResource(Activity.java:3683)
at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:140)
at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:85)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2271)
           
Here is my implementation for the same. Along with layouts. The minsdk is 11 and target is 22. Please let me know the reason for the issue.
Apart from Mainactivity.java class, I have SlidingTabLayout.java and SlidingTabStrip.java
activity_main.xml :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.easyaccom.abhishek.slidingtabswiper.MainActivity">
<com.easyaccom.abhishek.slidingtabswiper.SlidingTabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Custom tabview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:id="#+id/tabController">
<ImageView
android:id="#+id/tabImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView android:id="#+id/tabText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center"/>
fragment_my.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/position"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text=" The page Number is 1"
android:textColor="#color/colorPrimaryText"
android:textSize="20sp"/>
colors.xml (logcat shows issues with one of my colors I think):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#03A9F4</color>
<color name="colorPrimaryDark">#0288D1</color>
<color name="colorPrimaryLight">#B3E5FC</color>
<color name="colorAccent">#FF5722</color>
<color name="colorHighlight">#B6B6B6</color>
<color name="colorPrimaryText">#212121</color>
<color name="colorSecondaryText">#727272</color>
<color name="colorDivider">#B6B6B6</color>
<color name="colorba">#FFFFFF</color>
</resources>
Ok the answer to this question is very simple. I do not know for what reason but android studio by default had added colors.xml for 820dp wide devices (tablets) only. So there was no colors.xml for phones. It did not give me any error at compile time because there already was colors.xml off course for tablets not phones. Just as I added another colors.xml with same name, the issue was resolved. I think android studio needs to fix this probably they will in next updates.
Thanks.
The issue appears to be one of the colors you're setting. Unfortunately the logcat image is cut off, but the exception type is java.lang.UnsupportedOperationException .
edit: Try to comment out (or delete) this portion to see if it's the culprit:
mTabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer(){
#Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.colorAccent);
}
});`
hi i faced the same issue my problem was that android studio created a color.xml in values-w820dp so i changed to the project prespective and then copied colors.xml to values folder and it solv

Categories