Recently I pushed the app to live and it was'nt working on android 9 & above. So, I upgraded android studio to 2020.3.1, updated the plugins, migrated code to AndroidX. Since then I am facing following issue.
Here is the error at runtime
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.meltag.hil_distributor, PID: 7726
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.meltag.hil_distributor/com.meltag.hil_distributor.MainActivity}: android.view.InflateException: Binary XML file line #23 in com.meltag.hil_distributor:layout/abc_screen_toolbar: Binary XML file line #23 in com.meltag.hil_distributor:layout/abc_screen_toolbar: Error inflating class androidx.appcompat.widget.ActionBarOverlayLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
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:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.view.InflateException: Binary XML file line #23 in com.meltag.hil_distributor:layout/abc_screen_toolbar: Binary XML file line #23 in com.meltag.hil_distributor:layout/abc_screen_toolbar: Error inflating class androidx.appcompat.widget.ActionBarOverlayLayout
Caused by: android.view.InflateException: Binary XML file line #23 in com.meltag.hil_distributor:layout/abc_screen_toolbar: Error inflating class androidx.appcompat.widget.ActionBarOverlayLayout
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference
at uk.co.chrisjenx.calligraphy.ReflectionUtils.getValue(ReflectionUtils.java:29)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:203)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:237)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1067)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.inflate(LayoutInflater.java:657)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:899)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:809)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.meltag.hil_distributor.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
activity_main.xml
<androidx.drawerlayout.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- The main content view -->
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator_layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linear_lay1"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_lay1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_gravity="bottom"
android:background="@drawable/toolbar_gradient_bg"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ToolBarStyle">
<RelativeLayout
android:id="@+id/relative_lay1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/Main_navBtn"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="3dp"
android:padding="12dp"
android:src="@drawable/ic_menu"
tools:ignore="ContentDescription"/>
<TextView
android:id="@+id/tv_tittle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="18dp"
android:layout_marginLeft="60dp"
android:layout_marginStart="60dp"
android:text="Dashboard"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="visible"
tools:ignore="HardcodedText,RtlHardcoded"/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<!-- Real content goes here -->
<FrameLayout
android:id="@+id/container_body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fitsSystemWindows="true"/>
<!--<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="@drawable/ic_footer_login"/>-->
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<!-- The navigation drawer -->
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_navigation_drawer"
android:name="com.meltag.hil_distributor.fragments.FragmentDrawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer"/>
</androidx.drawerlayout.widget.DrawerLayout>
This is my onCreate()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final FragmentDrawer drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
Toolbar toolbar = findViewById(R.id.toolbar);
title = toolbar.findViewById(R.id.tv_tittle);
toolbar.findViewById(R.id.Main_navBtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerFragment.openDrawerFrag();
}
});
toolbar.setNavigationIcon(null);
toolbar.setContentInsetsAbsolute(0, 0);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
userPref = new AppPreferences(this);
DrawerLayout mDrawerLayout = findViewById(R.id.drawer_layout);
drawerFragment.setUp(R.id.fragment_navigation_drawer, mDrawerLayout);
drawerFragment.setDrawerListener(MainActivity.this);
displayView(0);
}
I can't figure out how to fix this. Any suggestions?
CalligraphyLayoutInflater
. Are you using some third party library?If yes then has it been migrated to AndroidX? – gtxtreme