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
Related
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)
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"
I'm developing an Android application and I try to use the toolbar to add some functionality on it; that's why I'm using appcompat-v7 module.
I have followed this tutorial (Sorry because it's in spanish) and I have updated my IDE with the Compatibility Support package, I also added the new module to my Gradle file and I have updated the design XML of my app with this new toolbar (I can see this toolbar in the design editor).
But, when I launch my application, I get following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
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:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.support.v7.widget.Toolbar
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/base.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_resources_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.gomar.gomar_sanidad-xZFFzOUSrlLb9osLbk1xcA==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(...
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.gomar.gomar_sanidad"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
A sample of my activity_main.xml with the toolbar(Design XML):
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".NuevaFicha">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"
app:layout_constraintVertical_bias="0.0">
....
I have tried what is said here (Checked ids, Cleaned project, Invalidated caches...) but none of these solutions had the desired results. Do you have any idea?
Thanks in advance.
you are using both androidx and AppCompat hence the error.consider using either.
implementation 'com.android.support:appcompat-v7:28.0.0' //this is appcompat
implementation 'androidx.appcompat:appcompat:1.0.0-beta01' //this is android x
you can not use androidx and android support at the same time.
see how to migrate to androidX
Your project is initialized as androidx project! if you dont want to use androidX components first remove this line from your gradle.properties file :
android.useAndroidX=true
Then replace all androidx dependencies with appcompat versions.
if you started a simple empty project you dont need to refactor this project simply create a new appcompat project instead of androidx project.
If your gradle.properties file has the property set as below
android.useAndroidX=true
Replace
android.support.v7.widget.Toolbar
With
androidx.appcompat.widget.Toolbar
Gradle build is successful logcat shows E/AndroidRuntime: FATAL EXCEPTION: main
--------Logcat Error-----------
07-27 23:04:54.813 21702-21702/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.inoalexander.justjava, PID: 21702
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.inoalexander.justjava/com.example.inoalexander.justjava.mainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.inoalexander.justjava.mainActivity" on path: DexPathList[[zip file "/data/app/com.example.inoalexander.justjava-2/base.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.inoalexander.justjava-2/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1424)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.inoalexander.justjava.mainActivity" on path: DexPathList[[zip file "/data/app/com.example.inoalexander.justjava-2/base.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.inoalexander.justjava-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1424)
---------Java Code starts here----------
package com.example.inoalexander.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
---------XML code starts here-------------
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="16sp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:text="Quantity" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="16sp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:text="0" />
<Button
android:id="#+id/button_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="16dp"
android:text="Order"
android:onClick="submitOrder"/>
</LinearLayout>
I'm not to sure as this is one of the first apps I've built that isn't a card. I'm not sure why it isn't running on my phone. I'm using a Galaxy Note 5 to run my build.
The Gradle build is successful and gives me no errors but when I try to run it on my device it keeps trying to restart the app until it eventually crashes the app. I have looked at a few answers here and was instructed to look at my Logcat in android studio.
I honestly don't know were to even begin within Logcat or what it even tells me, there are a lot of variations of this error I have seen but not one specific to each of the errors in my Logcat.
set multidex true to app level build.gradle file like below
android {
compileSdkVersion 27
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.core.######"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true // here change
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
also add dependency
implementation 'com.android.support:multidex:1.0.3'
finally don't forget to clean and rebuild project.
The exception says it's trying to find class mainActivity but in your code you have MainActivity.
Make sure the activity class name in AndroidManifest.xml matches your code.
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