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

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"

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)

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

Tabbed App: TabLayout / ViewPager - Error caused by upgrading Gradle & Support library

My code was working pre-update, i updated my grandle & support libraries etc and it stopped working.
trying to fix it only caused a loop reaction.
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
public class DashboardLightActivity extends AppCompatActivity {
private TabLayout tabLayout;
private ViewPager viewPager;
private ViewPageAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboardlight);
tabLayout = findViewById(R.id.tab_layout);
viewPager = findViewById(R.id.pager);
adapter = new ViewPageAdapter(getSupportFragmentManager());
adapter.AddFragment(new FragmentRed(), "Red");
adapter.AddFragment(new FragmentYellow(), "Yellow");
adapter.AddFragment(new FragmentGreen(), "Green");
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
tabLayout.getTabAt(0).setIcon(R.drawable.settings_icon);
tabLayout.getTabAt(1).setIcon(R.drawable.seatbelt_symbol);
tabLayout.getTabAt(2).setIcon(R.drawable.srs);
}
}
<LinearLayout
android:id="#+id/main_layout"
android:orientation="vertical"
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=".MainActivity">
<android.support.v4.view.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorGray"
android:minHeight="?attr/actionBarSize" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
my dependencies list. it might be wrong implementation but it should of worked
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-database:18.0.0'
implementation 'com.google.firebase:firebase-storage:18.0.0'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'org.jetbrains:annotations-java5:15.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
}
grandle project: bugged version?
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
The error i get while running the app:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mac.ben.carlendar, PID: 7688
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mac.ben.carlendar/com.mac.ben.carlendar.DashboardLightActivity}: android.view.InflateException: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Error inflating class android.support.v4.view.TabLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
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:2009)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
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:934)
Caused by: android.view.InflateException: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Error inflating class android.support.v4.view.TabLayout
Caused by: android.view.InflateException: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Error inflating class android.support.v4.view.TabLayout
Caused by: java.lang.ClassNotFoundException: android.support.v4.view.TabLayout
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.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.mac.ben.carlendar.DashboardLightActivity.onCreate(DashboardLightActivity.java:20)
at android.app.Activity.performCreate(Activity.java:7783)
at android.app.Activity.performCreate(Activity.java:7772)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3235)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
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:2009)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
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:934)
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.view.TabLayout" on path: DexPathList[[zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/base.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_dependencies_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_resources_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_0_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_1_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_2_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_3_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_4_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_5_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_6_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_7_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_8_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/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)
... 28 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:365)
at dalvik.system.DexFile.<init>(DexFile.java:107)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:403)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:851)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:950)
at android.app.LoadedApk.getResources(LoadedApk.java:1188)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2462)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2454)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6306)
at android.app.ActivityThread.access$1300(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1852)
... 6 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_1_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:365)
at dalvik.system.DexFile.<init>(DexFile.java:107)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:403)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:851)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:950)
at android.app.LoadedApk.getResources(LoadedApk.java:1188)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2462)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2454)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6306)
at android.app.ActivityThread.access$1300(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1852)
... 6 more
how to make the same code work as before, or what changes necessary to make it work again. the code haven't been changed.

Cannot show TabLayout in InputView

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

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