0

I have spent a long time looking for an answer to this issue and seem unable to figure it out.

An app I created through "Android Studio" has been working perfectly fine when I create an APK in debug mode, however if I create a bundle and upload it to play store then it crashes on 5 out of 11 devices (including my own) due to the exact same error:

Issue: java.lang.RuntimeException: Unable to start activity ComponentInfo{maxmansung.finaljudgement/maxmansung.finaljudgement.MainScreen}: android.view.InflateException: Binary XML file line #65: Binary XML file line #65: Error inflating class Button

What appears to be happening is that the app is unable to open any Buttons at all for some reason. I have tried deleting the button at the point of error but it simply changes to crashing on another button instead.


Error Log

FATAL EXCEPTION: main
Process: maxmansung.finaljudgement, PID: 20309
java.lang.RuntimeException: Unable to start activity ComponentInfo{maxmansung.finaljudgement/maxmansung.finaljudgement.MainScreen}: android.view.InflateException: Binary XML file line #65: Binary XML file line #65: Error inflating class Button
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:6524)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
Caused by: android.view.InflateException: Binary XML file line #65: Binary XML file line #65: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #65: Error inflating class Button
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=58; index=309
    at android.content.res.StringBlock.get(StringBlock.java:65)
    at android.content.res.AssetManager.getPooledStringForCookie(AssetManager.java:642)
    at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1279)
    at android.content.res.TypedArray.getString(TypedArray.java:219)
    at android.widget.TextView.(TextView.java:1157)
    at android.widget.Button.(Button.java:109)
    at android.widget.Button.(Button.java:105)
    at android.support.v7.widget.AppCompatButton.(AppCompatButton.java:71)
    at android.support.v7.widget.AppCompatButton.(AppCompatButton.java:67)
    at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
    at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
    at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at maxmansung.finaljudgement.MainScreen.onCreate(MainScreen.java:24)
    at android.app.Activity.performCreate(Activity.java:6910)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:6524)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

Game Code

If I keep the OnClickListener parts then the crash continues

package maxmansung.finaljudgement;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

import maxmansung.finaljudgement.savedVariables.saveSettings;

public class MainScreen extends AppCompatActivity {


@Override
public void onBackPressed() {
    System.exit(0);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_screen);

    saveSettings settings = new saveSettings(this);
    settings.updateFromSave(this);
    Boolean currentTrue = settings.getCurrentTrue();

    Button mainScreenNew = findViewById(R.id.mainScreenNew);
    Button mainScreenCont = findViewById(R.id.mainScreenCont);
    Button mainScreenAchievements = findViewById(R.id.mainScreenAchieve);

    if (currentTrue){
        mainScreenCont.setVisibility(View.VISIBLE);
    } else {
        mainScreenCont.setVisibility(View.GONE);
    }

    if (settings.achievementsGained()){
        mainScreenAchievements.setVisibility(View.VISIBLE);
    } else {
        mainScreenAchievements.setVisibility(View.GONE);
    }

    final Animation clickAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_click);

    mainScreenNew.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Animation.AnimationListener listener = new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    Intent gamePage = new Intent(getApplicationContext(),GamePage.class);
                    gamePage.putExtra("continue", false);
                    startActivity(gamePage);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            };
            clickAnimation.setAnimationListener(listener);
            view.startAnimation(clickAnimation);
        }
    });

XML Page

If I remove the drawableLeft and drawableStart parts then the crash changes to what appears to be an identical crash but further back in the XML code

I have removed the previous code as it does not impact the crash

<?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"
tools:context="maxmansung.finaljudgement.MainScreen">

<Button
    android:id="@+id/mainScreenAchieve"
    style="@style/Widget.AppCompat.Button.Borderless.Colored"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    android:drawableStart="@drawable/achievement_icon"
    android:drawableLeft="@drawable/achievement_icon"
    android:text="@string/mainScreenAchievements"
    android:textAllCaps="true"
    android:textColor="@color/colorText"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/mainScreenCont" />

Maxmansung
  • 63
  • 8

2 Answers2

0

This type of error sometimes happens because there is a drawable involved.
I see in your xml this @drawable/achievement_icon is used for the Button with id mainScreenAchieve.
Is there a case that you have stored this drawable in a folder like drawable-v24 only and not in the main drawable folder?
If this is the case then copy and paste it in the main drawable folder too.
Otherwise in the devices with lower version this drawable is unavailable and this leads to an app crash.

forpas
  • 160,666
  • 10
  • 38
  • 76
  • I've tried removing the drawable icon (and the entire button) but the crash continues, it appears to be specific to the act of inflating an button – Maxmansung Nov 24 '18 at 23:00
  • Yes, hence why I tested out removing the button with the drawable, however that resulted in this error: "android.view.InflateException: Binary XML file line #36: Error inflating class Button" – Maxmansung Nov 24 '18 at 23:08
  • Yes, the crash continues without the style and the error remains the same – Maxmansung Nov 24 '18 at 23:17
  • Then remove the attributes one by one and test. I would start by leaving only 1 Button and removing 1st its text and go on like this with the other attributes. – forpas Nov 24 '18 at 23:24
  • Ok, I will work my way through that. You think it must be specific to a single aspect of the buttons rather than a top level issue regarding the use of buttons in the app overal? – Maxmansung Nov 24 '18 at 23:27
  • Since you don't use any 3d party library or widget and this is the common Button I can't see why this would cause a problem but try it. Remove all the buttons and see what happens. – forpas Nov 24 '18 at 23:30
  • So it seems that after a **lot** of experiementing there are 2 things causing the crash 1. The use of `onClickListener` in the main code 2. The use of `drawableStart` and `drawableLeft` in the XML By removing both of these I can stop the crash – Maxmansung Nov 25 '18 at 10:39
  • *The use of drawableStart and drawableLeft* means problem with the drawable and *The use of onClickListener* means problem with the animation. – forpas Nov 25 '18 at 11:01
  • It would seem so, unfortunatly I don't have enough experience to be able to PM you so I'll just keep commenting. Is there any advice as to what could be causing both of these things or any details I could show that might help make it clearer? I've built the game so that its compatable with v16 and up, do I need seperate folders for images and animations for v21? – Maxmansung Nov 25 '18 at 11:04
  • Keep all the drawables and animations inside their main folders `drawable` and `anim`. Create other folders like `drawable-v21` and paste the drawbles there too and experiment. But deal with 1 problem at a time. First remove the animations and check the problem with the drawables. – forpas Nov 25 '18 at 11:10
  • Ok, so it appears there are 1 or 2 gradle errors due to an update of the android studio software twice during the development. This removed of one issue so it now works on 8 of 11 devices I believe the issue with the image in the button may be due to using a vector image (xml file) on the button. Is this a known issue? – Maxmansung Nov 25 '18 at 12:45
  • See this: https://stackoverflow.com/questions/41407811/android-vectordrawables-usesupportlibrary-true-is-stopping-app – forpas Nov 25 '18 at 12:57
0

It looks like it's related to the text setting. Is your strings.xml malformed? Or is it missing from certain build types?

Also - Having a + in this line: app:layout_constraintTop_toBottomOf="@+id/mainScreenCont" can cause problems. It doesn't need the +.

gtcompscientist
  • 671
  • 5
  • 18
  • I can remove the "+" but it doesn't make a difference to the crashes. I have also Isolated the crash down to 2 influences: 1. The images in 3rd button 2. The use of onClickListeners Both of these cause the crash and removing only one of them causes it to continue – Maxmansung Nov 25 '18 at 10:28
  • So, if you remove the `drawable` references from your snippet above, it works? If so, have you tried setting it programmatically, instead, to see if that still crashes? – gtcompscientist Nov 25 '18 at 14:17
  • It seems that after a lot of work I have discovered it is due to using a vector image within a button which doesn't work for pre v24 OS. I am also having a problem with the animations, I suspect this is also due to using it on a button – Maxmansung Nov 25 '18 at 19:28
  • Ah! Look up `useVectorCompat`. I'm away from my machine, or I would help more specifically with that set up. – gtcompscientist Nov 25 '18 at 21:06