Cannot show TabLayout in InputView - java

I'm creating an Android input method, and want to use TabLayout from the support library in the InputView (the UI where the user inputs text in the form of keyclicks).
The layout for the InputView is very simple:
<?xml version="1.0" encoding="utf-8"?>
<org.szm.enigma2.ime.InputView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout android:id="#+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentTop="true"
style="#style/Theme.AppCompat">
<android.support.design.widget.TabItem android:text="Hello"/>
<android.support.design.widget.TabItem android:text="World"/>
<android.support.design.widget.TabItem android:text="Enigma"/>
</android.support.design.widget.TabLayout>
</org.szm.enigma2.ime.InputView>
And I use the same layout for both InputView and the settings activity, which is a normal activity.
Create InputView from subclass of InputMethodService:
return getLayoutInflator().inflat(R.layout.input_view, null);
Inside the constructor of settings activity class:
setContentView(R.layout.input_view);
When I run the program, the settings activity is normal. Then tab layout is working perfectly. But when I activate the input method's input view, the program crashes with the following info:
09-08 18:56:49.064 28437-28437/org.szm.enigma2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.szm.enigma2, PID: 28437
android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class android.support.design.widget.TabLayout
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.design.widget.TabLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:652)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:812)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at org.szm.enigma2.ime.InputService.onCreateInputView(InputService.java:42)
at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1228)
at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1622)
at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1590)
at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:442)
at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:206)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6175)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:33)
at android.support.design.widget.TabLayout.<init>(TabLayout.java:297)
at android.support.design.widget.TabLayout.<init>(TabLayout.java:291)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
at android.view.LayoutInflater.createView(LayoutInflater.java:652) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:812) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:522) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:430) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
at org.szm.enigma2.ime.InputService.onCreateInputView(InputService.java:42) 
at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1228) 
at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1622) 
at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1590) 
at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:442) 
at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:206) 
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6175) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764) 
09-08 18:56:49.081 28437-28437/? I/Process: Sending signal. PID: 28437 SIG: 9
I don't know why it didn't work even if I set the style attribute. And how can I use tab layout in an input view? (since input view is not inside any activity)
Thanks
EDIT
I have already checked this question and googled other resources. Most of them is dealing with error of inflating TabLayout in Activity. My problem is that TabLayout works fine inside Activity but not in input view.

you can do it like this:
Context context = new ContextThemeWrapper(this, android.support.v7.appcompat.R.style.Theme_AppCompat_Light_NoActionBar);
LayoutInflater inflater = LayoutInflater.from(context);
view = (View) inflater.inflate(R.layout.XXXXX, null);
the Tablayout is in the R.layout.XXXXX

Related

android.view.InflateException: Caused by: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup

i am running flutter integrated app occuring crash on flutter fragment loading
xml page
<fragment
android:tag="home_fragment"
android:layout_width="match_parent"
android:layout_height="100dp"
android:name="com.angelbroking.spark.flutter.ui.view.home.FlutterXMLFragment"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
crash log :
2022-08-05 15:50:58.424 20601-20601/com.spark.angelbroking E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.spark.angelbroking, PID: 20601
android.view.InflateException: Binary XML file line #19 in com.spark.angelbroking:layout/fragment_login_auth: Binary XML file line #19 in com.spark.angelbroking:layout/fragment_login_auth: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #19 in com.spark.angelbroking:layout/fragment_login_auth: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
at android.view.ViewGroup.addView(ViewGroup.java:5020)
at android.view.ViewGroup.addView(ViewGroup.java:5002)
at io.flutter.plugin.platform.PlatformViewsController.attachToView(PlatformViewsController.java:545)
at io.flutter.embedding.android.FlutterView.attachToFlutterEngine(FlutterView.java:1170)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onCreateView(FlutterActivityAndFragmentDelegate.java:332)
at io.flutter.embedding.android.FlutterFragment.onCreateView(FlutterFragment.java:793)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2995)
at androidx.fragment.app.FragmentStateManager.ensureInflatedView(FragmentStateManager.java:388)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:260)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:142)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:241)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1088)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1024)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:988)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1150)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1111)
at android.view.LayoutInflater.inflate(LayoutInflater.java:709)
at android.view.LayoutInflater.inflate(LayoutInflater.java:547)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
at com.angelbroking.spark.common.base.NewBaseFragment.onCreateView(NewBaseFragment.kt:74)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2995)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:523)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:488)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8156)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)

Problem in opening an Activity from Fragment Activity

I have created a Fragment view in my Navigation Drawer and
I want to call an Activity from that Fragment view using an ImageView for that I have written this java code in My Fragment View class
But I don't know why whenever I click on my image the app gets crashed please help out
package com.example.gamesense.ui.Maps;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import com.example.gamesense.R;
public class MapsFragment extends Fragment {
private MapsViewModel mapsViewModel;
private ImageView erangle_image;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
mapsViewModel =
new ViewModelProvider(this).get(MapsViewModel.class);
View root = inflater.inflate(R.layout.fragment_maps, container, false);
//on click listener for image
erangle_image = root.findViewById(R.id.erangle_image);
erangle_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(getActivity(),ErangleMap.class));
}
});
return root;
}
}
And here is the XML for Fragment View and
from ImageView I want to open new Activity
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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:paddingLeft="20dp"
android:paddingTop="20dp"
android:paddingEnd="20dp"
android:background="#drawable/background"
android:paddingBottom="20dp"
android:paddingStart="20dp"
android:paddingRight="20dp"
android:orientation="vertical"
tools:context=".ui.Maps.MapsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/erangle"
android:background="#drawable/shape">
<ImageView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:scaleType="fitXY"
android:id="#+id/erangle_image"
android:src="#drawable/erangel"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ERANGLE:"
android:textAlignment="viewStart"
android:background="#C59507"
android:textSize="24sp"
android:textColor="#FFFFFF"
android:paddingTop="7dp"
android:paddingLeft="15dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#C59507"
android:paddingBottom="10dp"
android:text="Erangel is the first 8x8 km playable map created for PUBG."
android:textAlignment="textStart"
android:paddingLeft="15dp"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
Logcat
2021-03-23 09:48:47.556 10047-10047/com.example.gamesense E/Parcel: Reading a NULL string not supported here.
2021-03-23 09:48:47.586 10047-10086/com.example.gamesense E/libEGL: Invalid file path for libcolorx-loader.so
2021-03-23 09:48:47.596 10047-10047/com.example.gamesense D/AndroidRuntime: Shutting down VM
2021-03-23 09:48:47.597 10047-10047/com.example.gamesense E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gamesense, PID: 10047
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gamesense/com.example.gamesense.ui.Maps.ErangleMap}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3699)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:254)
at android.app.ActivityThread.main(ActivityThread.java:8202)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:843)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.gamesense.ui.Maps.ErangleMap.onCreate(ErangleMap.java:14)
at android.app.Activity.performCreate(Activity.java:8146)
at android.app.Activity.performCreate(Activity.java:8130)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3668)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:254) 
at android.app.ActivityThread.main(ActivityThread.java:8202) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006) 
2021-03-23 09:48:47.623 10047-10047/com.example.gamesense I/Process: Sending signal. PID: 10047 SIG: 92021-03-23 09:48:47.556 10047-10047/com.example.gamesense E/Parcel: Reading a NULL string not supported here.
2021-03-23 09:48:47.586 10047-10086/com.example.gamesense E/libEGL: Invalid file path for libcolorx-loader.so
2021-03-23 09:48:47.596 10047-10047/com.example.gamesense D/AndroidRuntime: Shutting down VM
2021-03-23 09:48:47.597 10047-10047/com.example.gamesense E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gamesense, PID: 10047
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gamesense/com.example.gamesense.ui.Maps.ErangleMap}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3699)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:254)
at android.app.ActivityThread.main(ActivityThread.java:8202)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:843)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.gamesense.ui.Maps.ErangleMap.onCreate(ErangleMap.java:14)
at android.app.Activity.performCreate(Activity.java:8146)
at android.app.Activity.performCreate(Activity.java:8130)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3668)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:254) 
at android.app.ActivityThread.main(ActivityThread.java:8202) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006) 
2021-03-23 09:48:47.623 10047-10047/com.example.gamesense I/Process: Sending signal. PID: 10047 SIG: 9```
it says "You need to use a Theme.AppCompat theme (or descendant) with this activity."
maybe you edited/removed the theme by mistake. check your manifest
have you declared this activity in your AndroidManifest.xml? check this one Check your manifest first and declare your activity
Add or modify existing theme with AppCompat theme in your styles.xml. like the following:
<style name="yourThemeName" parent="#style/Theme.AppCompat....">
//.... items will go here
</style>
And you can use this theme as global theme
<application
android:theme="#style/yourThemeName">
OR
For specific activity
<activity
android:name=".ErangleMap"
android:theme="#style/yourThemeName">
//....
</activity>

Error: inflating class com.google.android.material.navigation.NavigationView in androidX

My app working above API level 26 or higher but stoped working bellow API level 26. Please help me..
Why does XML returns error in inflating class, and stoped working in lower API level?
I tried these methods but it did not work:
Check your code for drawable and color resources used inside the com.google.android.material.navigation.NavigationView you've used, probably in activity_main.xml, if you're using the default Navigation Drawer template code from Android Studio.
Check that the drawable files are in res/drawable folder, not in res/drawable-v21.
Check if you've used android:backgroundTint() or android:src or similar inside your NavigationView. Since they don't work below android API Level 21, use app:backgroundTint or app:srcCompat instead.
...
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bozorgan/com.example.bozorgan.MainActivity}: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7223)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class com.google.android.material.navigation.NavigationView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.bozorgan.MainActivity.onCreate(MainActivity.java:63)
at android.app.Activity.performCreate(Activity.java:6877)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
at android.app.ActivityThread.access$1100(ActivityThread.java:223) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7223) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class com.google.android.material.navigation.NavigationView
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:id="#+id/navigation_drawer">
<include layout="#layout/activity_main"/>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/navigation_view"
android:layoutDirection="rtl"
app:headerLayout="#layout/navigation_header"
android:layout_gravity="end"
app:menu="#menu/menu" />
</androidx.drawerlayout.widget.DrawerLayout>
Be sure to add the Drawerlayout library to the build.gradle(:app) file so you can use Drawerlayout.
If not, open the build.gradle(:app) file and add:
implementation "androidx.drawerlayout: drawerlayout: 1.1.1"
in AndroidX NavigationView requires these dependencies and also check out Documentation for more Information here
// Java language implementation
implementation "androidx.navigation:navigation-fragment:2.3.2"
implementation "androidx.navigation:navigation-ui:2.3.2"
// Kotlin
implementation "androidx.navigation:navigation-fragment-ktx:2.3.2"
implementation "androidx.navigation:navigation-ui-ktx:2.3.2"

Implementing countries to spinner in activity

I am trying to implement: https://github.com/hbb20/CountryCodePickerProject to my project to show a list of all countries in a spinner.
I added code to my build.gradle (app):
implementation 'com.hbb20:ccp:2.3.4'
After that I added it to XML file (layout) as it state on https://github.com/hbb20/CountryCodePickerProject/wiki/Use-as-a-Country-Selector:
<com.hbb20.CountryCodePicker
android:id="#+id/country"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
app:ccp_showFullName="true"
app:ccp_showNameCode="false"
app:ccp_showPhoneCode="false"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="0dp" />
When I run my application it looks like:
But when I click on the spinner to select country application crash and in Logcat I get an error:
2019-12-27 14:47:00.619 13536-13536/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cryptowallet, PID: 13536
android.view.InflateException: Binary XML file line #78: Binary XML file line #78: Error inflating class com.futuremind.recyclerviewfastscroll.FastScroller
Caused by: android.view.InflateException: Binary XML file line #78: Error inflating class com.futuremind.recyclerviewfastscroll.FastScroller
Caused by: java.lang.reflect.InvocationTargetException
Add below 2 lines in gradle.properties file.
android.useAndroidX=true
android.enableJetifier=true

Unable to call the fragment with imageView in android

Today is my first time to be using the fragments. And I was able to make a simple app that utilizes the fragment, however, there is one problem that I cannot understand or hadn't noticed yet. The problem is the app crashes when I add the fragment with the imageView. Everything works fine when I use simple texts or other widgets. I've set the sample code below.
I'm calling the fragment from Activity1 like this.
android.support.v4.app.FragmentManager fragmentManager2 = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction2 = fragmentManager2.beginTransaction();
TestFragment fragment = new TestFragment();
fragmentTransaction2.add(R.id.fragment_container, fragment,"HELLO");
fragmentTransaction2.commit();
This is the layout that fills the fragment
<LinearLayout
android:id="#+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
This is the simple Activity2 class that extends the fragment
public class Activity2 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/** Inflating the layout for this fragment **/
View v = inflater.inflate(R.layout.fragment_class2, null);
return v;
}
}
this is the layout for the class that extends the fragment .
Ps: The imageview in here causes the error, however, the settings in the fragment class may be the problem. I need to display the imageView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imaew2"
android:src="#drawable/playimage2"
/>
</LinearLayout>
These are the error I get and I'm not sure how these errors mean, however the error is pointing to the Fragment
         
 
 at com.trymeagain.Activity2.onCreateView(Activity2.java:13)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
Added new Error
05-07 17:56:20.701 3173-3173/com.trymeagain E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 74649612 byte allocation with 1048576 free bytes and 63MB until OOM"
05-07 17:56:20.703 3173-3173/com.trymeagain D/skia﹕ --- allocation failed for scaled bitmap
05-07 17:56:20.704 3173-3173/com.trymeagain D/AndroidRuntime﹕ Shutting down VM
05-07 17:56:20.704 3173-3173/com.trymeagain E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.trymeagain, PID: 3173
android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
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 com.trymeagain.PlusOneFragment.onCreateView(Activity2.java:13)
you getting the exception in your imageview where your image playimage2 is too large and the heap memory is not enough to allocate ...
solution-
case1 : if size need to increase on higher resolution device
if playimage2 is possible to patch-then try to reduce the size of the image..you can use tool like photoshop to do so.and then patch the image
case2 : if size need to be constant as written in xml 50dp*50dp
Just try to reduce the size of the image

Categories