App crashing when I'm trying to use custom EditText - android

I'm using custom editText, and receive crush on a start. It's also ruins my constraints on a design page of xml. With default one everything is ok.
Code for custom EditText: Using it to lock cursor in the end.
class CustomEditText(context: Context) : EditText(context) {
public override fun onSelectionChanged(start: Int, end: Int) {
val text = text
if (text != null) {
if (start != text.length || end != text.length) {
setSelection(text.length, text.length)
return
}
}
super.onSelectionChanged(start, end)
}
}
Code in xml:
<sh1gure.test.creditcardform.view.CustomEditText
android:id="#+id/etCardDate"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginEnd="8dp"
android:background="#drawable/edit_text_back"
android:ems="10"
android:hint="#string/mm_yy"
android:inputType="number"
android:maxLength="#integer/max_length_date"
android:paddingLeft="8dp"
android:paddingRight="8dp"
app:layout_constraintBottom_toTopOf="#+id/btn_add_card"
app:layout_constraintEnd_toStartOf="#+id/etCardCvv"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/etCardNumber1"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
Logcat:
Process: sh1gure.test.creditcardform, PID: 24143
java.lang.RuntimeException: Unable to start activity ComponentInfo{sh1gure.test.creditcardform/sh1gure.test.creditcardform.view.MainActivity}: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class sh1gure.test.creditcardform.view.CustomEditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
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:1818)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6762)
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 #53: Binary XML file line #53: Error inflating class sh1gure.test.creditcardform.view.CustomEditText
Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class sh1gure.test.creditcardform.view.CustomEditText

For XML inflation, you must provide a constructor with an AttributeSet as second parameter:
class CustomEditText(context: Context, attrs: AttributeSet? = null) : EditText(context, attrs) {
public override fun onSelectionChanged(start: Int, end: Int) {
val text = text
if (text != null) {
if (start != text.length || end != text.length) {
setSelection(text.length, text.length)
return
}
}
super.onSelectionChanged(start, end)
}
}

Related

force close while intent from activity to activity

so i want to intent from settings activity into edit profile activity, but when i clicked the edit profile button in settings activity, suddenly my application is force closed. for the information, i have profile fragment attached to main activity. on profile fragment, it has button that intent to settings activity. but, in settings activity it also has button that intent to edit profile activity. the problem is i can't intent from the settings activity to edit profile activity.
here's the SettingsActivity.kt
class SettingsActivity : AppCompatActivity(), View.OnClickListener {
private lateinit var settingsBinding: ActivitySettingsBinding
private var refUsers : DatabaseReference? = null
private var firebaseUser : FirebaseUser? = null
companion object{
fun getLaunchService (from: Context) = Intent(from, SettingsActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
settingsBinding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(settingsBinding.root)
supportActionBar?.hide()
settingsBinding.cvSettingsLogOut.setOnClickListener(this)
settingsBinding.btnEditProfile.setOnClickListener(this)
userInfo()
}
private fun userInfo(){
firebaseUser = FirebaseAuth.getInstance().currentUser
refUsers = FirebaseDatabase.getInstance().getReference("User").child(firebaseUser!!.uid)
refUsers!!.addValueEventListener(object : ValueEventListener {
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
override fun onDataChange(snapshot: DataSnapshot) {
for (p0 in snapshot.children){
val userName = snapshot.child("userName").value.toString()
val email = snapshot.child("email").value.toString()
val profileImage = snapshot.child("profile_image").value.toString()
settingsBinding.tvProfileUsername.text = userName
settingsBinding.tvProfileEmail.text = email
Glide.with(this#SettingsActivity).load(profileImage).into(settingsBinding.ivProfileSettings)
}
}
})
}
override fun onClick(v: View) {
when(v.id){
R.id.btnEditProfile -> startActivity(EditProfileActivity.getLaunchService(this))
R.id.cvSettingsLogOut -> logOut()
}
}
private fun logOut() {
/* Create a new instance of the AlertDialog class. */
var alertDialog: AlertDialog? = null
val builder = AlertDialog.Builder(this)
/* Inflate the layout file for the dialog box. */
val view = DialogConfirmLogoutBinding.inflate(layoutInflater)
/* Set the view of the dialog box. */
builder.setView(view.root)
view.btnConfirmCancel.setOnClickListener {
alertDialog?.dismiss()
}
view.btnConfirmYes.setOnClickListener {
alertDialog?.dismiss()
FirebaseAuth.getInstance().signOut()
val intent = Intent(this, LoginActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
finish()
}
/* Showing the dialog box. */
alertDialog = builder.create()
alertDialog.show()
}
}
my EditProfileAcitivity.kt
class EditProfileActivity : AppCompatActivity() {
private lateinit var editProfileBinding: ActivityEditProfileBinding
companion object{
fun getLaunchService (from: Context) = Intent(from, EditProfileActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
editProfileBinding = ActivityEditProfileBinding.inflate(layoutInflater)
setContentView(editProfileBinding.root)
supportActionBar?.hide()
}
}
here's the layout for EditProfile xml
<?xml version="1.0" encoding="utf-8"?>
<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=".activity.EditProfileActivity">
<ImageView
android:id="#+id/ivBackEditProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_20dp"
android:src="#drawable/ic_back"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_20dp"
android:fontFamily="#font/poppins_medium"
android:text="#string/edit_profile"
android:textColor="#color/black"
android:textSize="#dimen/_18sp"
app:layout_constraintBottom_toBottomOf="#+id/ivBackEditProfile"
app:layout_constraintStart_toEndOf="#+id/ivBackEditProfile"
app:layout_constraintTop_toTopOf="#+id/ivBackEditProfile" />
<LinearLayout
android:id="#+id/llAddEditProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_20dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/ivBackEditProfile">
<ImageView
android:id="#+id/ivAddBgEditProfile"
android:layout_width="match_parent"
android:layout_height="#dimen/_150dp"
android:scaleType="fitXY"
android:src="#drawable/bg_addbgeditprofile">
</ImageView>
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/ivAddProfilePhoto"
android:layout_width="#dimen/_100dp"
android:layout_height="#dimen/_100dp"
android:layout_marginStart="#dimen/_20dp"
android:scaleType="fitCenter"
android:src="#drawable/bg_addprofilephtoeditpro" />
</LinearLayout>
<EditText
android:id="#+id/etNameEditProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="#dimen/_25dp"
android:background="#drawable/bg_et_editprofile"
android:hint="Name"
android:layout_marginTop="#dimen/_20dp"
android:inputType="textPersonName"
android:maxLines="1"
android:maxLength="15"
android:padding="#dimen/_15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/llAddEditProfile" />
<EditText
android:id="#+id/etBioEditProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_et_editprofile"
android:hint="Bio"
android:layout_marginHorizontal="#dimen/_25dp"
android:maxLines="3"
android:inputType="textMultiLine"
android:layout_marginTop="#dimen/_20dp"
android:maxLength="100"
android:padding="#dimen/_15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/etNameEditProfile" />
<EditText
android:id="#+id/etLinkEditProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_et_editprofile"
android:hint="Link"
android:layout_marginHorizontal="#dimen/_25dp"
android:maxLines="1"
android:inputType="textUri"
android:layout_marginTop="#dimen/_20dp"
android:maxLength="15"
android:padding="#dimen/_15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/etBioEditProfile" />
<Button
android:id="#+id/btnSaveEditProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="#dimen/_25dp"
android:layout_marginEnd="#dimen/_25dp"
android:background="#drawable/bg_btnaddpost"
android:fontFamily="#font/poppins_semibold"
android:paddingHorizontal="#dimen/_50dp"
android:text="Save"
android:textAllCaps="false"
android:textSize="#dimen/_18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
this is the log error that i got cuz of sudden force close on my app while intent to editprofile activity. if u know what's goin on with my code, pls help me. Thanks.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.isjieman.ocion, PID: 5334
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.isjieman.ocion/com.isjieman.ocion.activity.EditProfileActivity}: android.view.InflateException: Binary XML file line #55 in com.isjieman.ocion:layout/activity_edit_profile: Binary XML file line #55 in com.isjieman.ocion:layout/activity_edit_profile: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.view.InflateException: Binary XML file line #55 in com.isjieman.ocion:layout/activity_edit_profile: Binary XML file line #55 in com.isjieman.ocion:layout/activity_edit_profile: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #55 in com.isjieman.ocion:layout/activity_edit_profile: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at com.isjieman.ocion.databinding.ActivityEditProfileBinding.inflate(ActivityEditProfileBinding.java:80)
at com.isjieman.ocion.databinding.ActivityEditProfileBinding.inflate(ActivityEditProfileBinding.java:74)
at com.isjieman.ocion.activity.EditProfileActivity.onCreate(EditProfileActivity.kt:20)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalArgumentException: ScaleType FIT_CENTER not supported.
at de.hdodenhof.circleimageview.CircleImageView.setScaleType(CircleImageView.java:134)
at android.widget.ImageView.<init>(ImageView.java:223)
at android.widget.ImageView.<init>(ImageView.java:190)
at de.hdodenhof.circleimageview.CircleImageView.<init>(CircleImageView.java:98)
at de.hdodenhof.circleimageview.CircleImageView.<init>(CircleImageView.java:94)
... 29 more
You are getting because you have set android:scaleType="fitCenter" in below code and CircleImageView not supporting fitCenter
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/ivAddProfilePhoto"
android:layout_width="#dimen/_100dp"
android:layout_height="#dimen/_100dp"
android:layout_marginStart="#dimen/_20dp"
android:scaleType="fitCenter"
android:src="#drawable/bg_addprofilephtoeditpro" />
kindly read limitation of library first
https://github.com/hdodenhof/CircleImageView#limitations

App does not open on Android 6.0.1. But works on emulator and Android 10

I created an app with five fragments and bottomnavigationview on android java , and this works fine android 10 and emulator. When I tried running on android 6.0.1 , the app crashes.
I tried available solutions on internet but all in vein. I had been stuck here for large amount of time and any help towards the solution is appreciated.
Any other lines of code required for clarification can be provided, if asked.
This is the logcat
2022-06-24 11:12:45.252 29202-29202/com.package.packagename E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package.packagename, PID: 29202
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.packagename/com.package.packagename.activities.HomeActivity}: android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2492)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2552)
at android.app.ActivityThread.access$1000(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737)
Caused by: android.view.InflateException: Binary XML file line #27: Binary XML file line #27: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.view.LayoutInflater.inflate(LayoutInflater.java:545)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:64)
at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:58)
at com.package.packagename.activities.HomeActivity.onCreate(HomeActivity.java:30)
at android.app.Activity.performCreate(Activity.java:6308)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2445)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2552) 
at android.app.ActivityThread.access$1000(ActivityThread.java:166) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737) 
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:654)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:809)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:880)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843)
at android.view.LayoutInflater.inflate(LayoutInflater.java:521)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:64) 
at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:58) 
at com.package.packagename.activities.HomeActivity.onCreate(HomeActivity.java:30) 
at android.app.Activity.performCreate(Activity.java:6308) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2445) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2552) 
at android.app.ActivityThread.access$1000(ActivityThread.java:166) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:628)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:809) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:749) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:880) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:843) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:521) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:64) 
at com.package.packagename.databinding.ActivityHomeBinding.inflate(ActivityHomeBinding.java:58) 
at com.package.packagename.activities.HomeActivity.onCreate(HomeActivity.java:30) 
at android.app.Activity.performCreate(Activity.java:6308) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2445) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2552) 
at android.app.ActivityThread.access$1000(ActivityThread.java:166) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1399) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:737) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070069
at android.content.res.Resources.getValue(Resources.java:1375)
at android.content.res.VivoResources.getValue(VivoResources.java:191)
at androidx.appcompat.widget.ResourceManagerInternal.loadDrawableFromDelegates(ResourceManagerInternal.java:256)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:143)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:136)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:66)
at androidx.appcompat.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:505)
at com.google.android.material.navigation.NavigationBarItemView.initialize(NavigationBarItemView.java:196)
at com.google.android.material.navigation.NavigationBarMenuView.buildMenuView(NavigationBarMenuView.java:707)
at com.google.android.material.navigation.NavigationBarPresenter.updateMenuView(NavigationBarPresenter.java:72)
at com.google.android.material.navigation.NavigationBarView.inflateMenu(NavigationBarView.java:386)
at com.google.android.material.navigation.NavigationBarView.<init>(NavigationBarView.java:280)
at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:108)
at com.google.android.material.bottomna
This is the HomeActivity.java
public class HomeActivity extends AppCompatActivity {
private ActivityHomeBinding binding;
Fragment fragment;
#SuppressLint("NonConstantResourceId")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityHomeBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("BIKE TAXI ADMIN");
setSupportActionBar(toolbar);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
bottomNavigationView.setSelectedItemId(R.id.home);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();
bottomNavigationView.setOnItemSelectedListener(item -> {
switch (item.getItemId()) {
case R.id.home:
//toolbar.setTitle("Shop");
fragment = new HomeFragment();
loadFragment(fragment);
return true;
case R.id.offer:
// toolbar.setTitle("My Gifts");
fragment = new OffersFragment();
loadFragment(fragment);
return true;
case R.id.reviews:
// toolbar.setTitle("My Gifts");
fragment = new ReviewsFragment();
loadFragment(fragment);
return true;
case R.id.notifications:
// toolbar.setTitle("Cart");
fragment = new NotificationsFragment();
loadFragment(fragment);
return true;
case R.id.earnings:
// toolbar.setTitle("Profile");
fragment = new EarningsFragment();
loadFragment(fragment);
return true;
}
return false;
});
}
private void loadFragment(Fragment fragment) {
// load fragment
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
This is the activity_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/page_gradient">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/MyAppTheme.AppBarOverlay">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_material" />
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:layout_below="#id/appBarLayout"
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottomNavigationView" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#drawable/nav_background"
app:itemIconTint="#color/nav_color"
app:itemTextColor="#color/nav_color"
app:menu="#menu/bottom_nav_menu" />
</RelativeLayout>
your problem lies in here Resources$NotFoundException - you are probably using some icons for BottomNavigationView and you don't have all density variants. e.g. you have some icon in drawable-hdpi and app works on devices/emulators with HDPI screen, but crashes on XXDPI as there is no image in drawable-xxhdpi. no matter OS version
there is also a chance for similar problem related to other resources, e.g. text - you have translated some text in values-en/strings.xml, but there is no equivalent line in default values/strings.xml - app works on en-lang devices, crashes on other
due to general Resources$NotFoundException I suggest to inspect all your resources, at first drawables

ViewBinding with generated CustomViews in Android | android.view.InflateException

I am referring to both questions:
Android ViewBinding with CustomView and
How to use View Binding on custom views
I am currently migrating from Kotlin synthetics to view binding and I am using alot of custom generated views, mainly to ajust the view size when pressed. It looks like the following (prior to that was java code, if I did something wrong while switching to kotlin please feel free to correct me):
class CustomButton constructor(context: Context, attrs: AttributeSet?): AppCompatButton(context, attrs) {
#SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
super.onTouchEvent(event)
if (event.action == MotionEvent.ACTION_CANCEL) {
val regainer =
AnimatorInflater.loadAnimator(context, R.animator.regain_size) as AnimatorSet
regainer.setTarget(this)
regainer.start()
return true
}
when (event.action) {
MotionEvent.ACTION_DOWN -> {
val reducer = AnimatorInflater.loadAnimator(context, R.animator.reduce_size) as AnimatorSet
reducer.setTarget(this)
reducer.start()
return true
}
MotionEvent.ACTION_UP -> {
val regainer = AnimatorInflater.loadAnimator(context, R.animator.regain_size) as AnimatorSet
regainer.setTarget(this)
regainer.start()
return true
}
}
return false
}
override fun performClick(): Boolean {
super.performClick()
return true
}
Unfortunatly all the questions I looked up so far only reffer to a solution including a custom .xml file. My binding in the activity looks like this:
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.customButton.//...
}
What I am currently getting is an android.view.InflateException through that custom view. Does anyone have an idea on how to implement view binding in this case or how to initialize it in the CustomButton class? Any help with this is much appreciated!
Best regards,
Markus
This is the stack trace of the error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.my.app, PID: 13035
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.MainActivity}: android.view.InflateException: Binary XML file line #39 in com.my.app:layout/activity_main: Binary XML file line #39 in com.my.app:layout/activity_main: Error inflating class com.my.app.custom.CustomTextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2246)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8010)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
Caused by: android.view.InflateException: Binary XML file line #39 in com.my.app:layout/activity_main: Binary XML file line #39 in com.my.app:layout/activity_main: Error inflating class com.my.app.custom.CustomTextView
Caused by: android.view.InflateException: Binary XML file line #39 in com.my.app:layout/activity_main: Error inflating class com.my.app.custom.CustomTextView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at com.my.app.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:78)
at com.my.app.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:72)
at com.my.app.MainActivity.onCreate(MainActivity.kt:59)
at android.app.Activity.performCreate(Activity.java:8006)
at android.app.Activity.performCreate(Activity.java:7990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3584)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2246)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8010)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f0302ca a=-1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:625)
at android.widget.TextView.readTextAppearance(TextView.java:4000)
E/AndroidRuntime: at android.widget.TextView.<init>(TextView.java:1093)
at android.widget.TextView.<init>(TextView.java:994)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:102)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:97)
at com.my.app.custom.CustomTextView.<init>(CustomTextView.kt:13)
... 27 more
CustomTextView.kt:13 is this line:
class CustomTextView constructor(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) {
MainActivity.kt:59 is this line:
binding = ActivityMainBinding.inflate(layoutInflater)
The activity_main.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:fillViewport="true"
app:layout_constrainedHeight="true"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/mainGuidelineVerticalLeft"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.05"/>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/mainGuidelineVerticalRight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.95"/>
<com.my.app.custom.CustomTextView
android:id="#+id/mainSubmenuSettings"
android:layout_width="wrap_content"
android:layout_height="#dimen/minimum"
android:gravity="center"
android:paddingHorizontal="12dp"
android:layout_marginEnd="12dp"
android:text="#string/textViewSettings"
android:textColor="?attr/primaryTextColorDefault"
android:textSize="#dimen/textViewS"
android:textStyle="bold"
android:focusable="true"
android:clickable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.my.app.custom.CustomCardView
android:id="#+id/mainCardView1"
android:layout_width="0dp"
android:layout_height="#dimen/cardViewHeightLarge"
android:layout_marginVertical="#dimen/cardViewMarginVertical"
android:clickable="true"
android:focusable="true"
android:elevation="#dimen/elevation"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="#dimen/cardViewCornerRadiusLarge"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toTopOf="#id/mainCardView2"
app:layout_constraintEnd_toStartOf="#+id/mainGuidelineVerticalRight"
app:layout_constraintStart_toStartOf="#+id/mainGuidelineVerticalLeft"
app:layout_constraintVertical_chainStyle="packed">
</com.my.app.custom.CustomCardView>
<com.my.app.custom.CustomCardView
android:id="#+id/mainCardView2"
android:layout_width="0dp"
android:layout_height="#dimen/cardViewHeightLarge"
android:layout_marginTop="#dimen/cardViewMarginVertical"
android:layout_marginBottom="10dp"
android:clickable="true"
android:focusable="true"
android:elevation="#dimen/elevation"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="#dimen/cardViewCornerRadiusLarge"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/mainGuidelineVerticalRight"
app:layout_constraintStart_toStartOf="#+id/mainGuidelineVerticalLeft"
app:layout_constraintVertical_chainStyle="packed">
</com.my.app.custom.CustomCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Nothing in the stack trace points to View Binding as being the problem here. Instead, it looks like a theme issue:
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f0302ca a=-1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:625)
at android.widget.TextView.readTextAppearance(TextView.java:4000)
The first place I'd look is here:
<com.my.app.custom.CustomTextView
android:textColor="?attr/primaryTextColorDefault"
... />
Make sure that you actually define <item name="primaryTextColorDefault"> in your theme.

In this news app, I keep getting InflateException

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.newsapp/com.example.newsapp.ui.MainActivity}:
android.view.InflateException: Binary XML file line #25 in
com.example.newsapp:layout/activity_main: Binary XML file line #25 in
com.example.newsapp:layout/activity_main: Error inflating class
fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
class MainActivity : AppCompatActivity() {
lateinit var viewModel : NewsViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val newsRepository = NewsRepository(ArticleDatabase(this))
val viewModelProviderFactory = NewsViewModelProviderFactory(newsRepository)
viewModel = ViewModelProvider(this, viewModelProviderFactory).get(NewsViewModel::class.java)
bottomNavigationView.setupWithNavController(nav_host_fragment_container.findNavController())
}
<FrameLayout
android:id="#+id/flFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<fragment
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/nav_host_fragment_container"
app:defaultNavHost="true"
app:navGraph="#navigation/news_nav_graph"/>
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="56dp"
app:backgroundTint="#color/grey"
app:menu="#menu/bottom_navigation_menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"/>
You have two mistakes in the code
First, you name the listview and the listfiles with the same variable name
// look at that in these lines, both of them had the same variable name
private lateinit var list: ListView
val list = dir.listFiles()
Second, the part which makes the exception in this line
val list = dir.listFiles() // dir.listFiles() returns null
check this answer if you want to get a list of files in directory as I understand

Google maps fragment in epoxy view

I'm currently exploring the new MvRx stack from Airbnb
Rigth now i am adding a google maps fragment successfully to a BaseMvRxFragment in a BottomNavigationView.
The problem is that the 2. time i navigate to the MapFragment my app crashes and i get the following error message:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: getflareapp.com.s2s, PID: 19184
android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f080093, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3752)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.view.View.inflate(View.java:23239)
at getflareapp.com.s2s.views.MapView.<init>(MapView.kt:19)
at getflareapp.com.s2s.views.MapView.<init>(MapView.kt:14)
at getflareapp.com.s2s.views.MapView.<init>(Unknown Source:6)
at getflareapp.com.s2s.views.MapViewModel_.buildView(MapViewModel_.java:42)
at getflareapp.com.s2s.views.MapViewModel_.buildView(MapViewModel_.java:22)
MapFragment.kt
/**
* A simple [BaseFragment] subclass.
*
*/
class MapFragment : BaseFragment() {
private val mViewModel: ChatViewModel by fragmentViewModel()
override fun epoxyController() = simpleController(mViewModel) {state ->
mapView{
id("map")
}
}
}
MapView.kt
#ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_MATCH_HEIGHT)
class MapView #JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
init {
// TODO: Fix crash on second view.
inflate(context, R.layout.view_map, this)
}
}
view_map.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map2"
android:name="getflareapp.com.s2s.ui.map.MapFragment"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity" />
</FrameLayout>
Thanks for any help! <3
I´ve problems adding directly the map fragment inner other fragment, so i suggest change that with Framelayout and inflate the fragment manually.

Categories

Resources