Good luck, let's see, I was looking at the Google Play console and it reported the following error from a tablet:
Caused by: android.view.InflateException:
at android.view.LayoutInflater.inflate (LayoutInflater.java:539)
at android.view.LayoutInflater.inflate (LayoutInflater.java:423)
at android.view.LayoutInflater.inflate (LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView (AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:140)
at com.isaac.tiquismiquis.MainActivity.onCreate (MainActivity.java:211)
at android.app.Activity.performCreate (Activity.java:6284)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2518)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate (LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
at android.view.LayoutInflater.inflate (LayoutInflater.java:515)
Caused by: android.content.res.Resources$NotFoundException:
at android.content.res.Resources.loadDrawableForCookie (Resources.java:2834)
at android.content.res.Resources.loadDrawable (Resources.java:2756)
at android.content.res.TypedArray.getDrawable (TypedArray.java:870)
at android.widget.ImageView.<init> (ImageView.java:152)
at android.widget.ImageView.<init> (ImageView.java:140)
at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:72)
at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageView (AppCompatViewInflater.java:182)
at android.support.v7.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImpl.createView (AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView (AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:746)
Looking for information, I suspect that this error is due to the density of the tablet screen (it is 8 inches), since in the onCreate I have so that when you press a button and it edittext
is empty, change the image to another, or it is directly that I have added the image in only one size, since I only added it in one of them "bareback" in the drawable
.
I am also going to put the content of the onCreate of my MainActivity and the content of the XML, in case there is any error in it:
Here you have, on the one hand, the content of the XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:background="@color/background"
tools:context=".MainActivity">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="350dp"
android:layout_height="100dp"
android:id="@+id/ivLogo"
android:scaleType="centerCrop"
android:src="@drawable/logotipo"
android:layout_marginBottom="50dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/tvBeforeTranslate"/>
<TextView
android:id="@+id/tvBeforeTranslate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textNoTranslate"
app:layout_constraintLeft_toLeftOf="parent"
android:fontFamily="@font/truenosbd"
android:textColor="#6D6D6D"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/ivLogo" />
<EditText
android:id="@+id/etBeforeTranslate"
android:layout_width="350dp"
android:layout_height="200dp"
android:layout_marginTop="30dp"
android:gravity="start"
android:paddingTop="10dp"
android:paddingStart="10dp"
android:textSize="16sp"
android:fontFamily="@font/truenoultlt"
app:layout_constraintLeft_toLeftOf="parent"
android:background="#FFFFFF"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvBeforeTranslate" />
<Button
android:id="@+id/btnTranslate"
android:layout_width="250dp"
android:layout_height="80dp"
android:layout_marginTop="30dp"
android:textColor="#FFFFFF"
android:fontFamily="@font/truenosbd"
android:background="@color/buttons"
android:text="Traducir"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/btnVoice"
app:layout_constraintTop_toBottomOf="@id/etBeforeTranslate" />
<ImageButton
android:id="@+id/btnVoice"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:background="@color/buttons"
android:src="@drawable/ic_keyboard_voice"
app:layout_constraintStart_toEndOf="@id/btnTranslate"
app:layout_constraintTop_toBottomOf="@id/etBeforeTranslate" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
And on the other hand I put the content of the onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
btnVoice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (count == 0) {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
checkPermission();
} else {
speechToText();
btnVoice.setImageResource(R.drawable.ic_keyboard_voice_press);
etBeforeTranslate.setText("");
etBeforeTranslate.setHint("Venga anda, te escucho, mimimi...");
}
count = 1;
} else if (count == 1) {
mSpeechRecognizer.cancel();
mSpeechRecognizer.destroy();
btnVoice.setImageResource(R.drawable.ic_keyboard_voice);
etBeforeTranslate.setHint("");
count = 0;
}
}
});
btnTranslate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String texto = textTranslate();
if (etBeforeTranslate.getText().toString().trim().isEmpty()) {
ivLogo.setImageResource(R.drawable.logotipoangry);
Toast.makeText(MainActivity.this, "¡Ay que agobio! Intridici il tixti, anda", Toast.LENGTH_SHORT).show();
} else {
Translates = FirebaseDatabase.getInstance().getReference("Translates");
registerTranslates();
ivLogo.setImageResource(R.drawable.logotipo);
Intent intent = new Intent(MainActivity.this, TranslateActivity.class);
intent.putExtra("texto", texto);
startActivity(intent);
}
}
});
}
Let's see if you can give me a hand with this and if after all my suspicions were true, the truth is that in my short journey through the world of programming, I had never run my app other than on my mobile, but of course now that the I have uploaded to the store, I get other errors, although it is good for me to learn. Thank you very much.
This indicates that the error occurs on certain devices
Now as for the stacktrace error message, it indicates that there is no resource which is trying to be loaded from a layout :
You should check that the same image is found in all directories
/drawable
that have suffixes, for example:The problem is because one of these directories is
/drawable-...
missing an image required for a certain density/size of device.If you want to avoid this, one option is to add all the images in the directory
/drawable
and any device density/size would get it with no problem.Although the correct thing is definitely to add the required image in each directory so that it is displayed correctly according to its size / density.
Check:
How to support different pixel densities
Add vector graphics of various densities