0

This is my first venture into writing any kind of code, let alone an android app. I created the project with the compileSdkVersion of 28, targetSdkVersion of 28 and minSdkVersion of 23. The app will only run on Android Pie and crashes on any previous version I have tried to install it on.

Everything compiles properly and works wonderfully on the emulator and my personal phone (both on Pie). I have read a lot about using the Android Support Library, however, I have not seen any information on how to understand which parts of your code need to use things from the support library versus the framework. Android Studio may have given me warnings along the way about using things from the support library, but being new at this, I did not know what it meant or what my proper choice should be. Now that I understand, I don't know how to attack going back and finding (and then fixing) anything that needs to use the support libraries.

I imported com.android.support:appcompat-v7 and have used AppCompatActivity instead of Activity. In a nutshell, I use textViews, editTexts, spinners and a TabHost (with two tabs). I think that the ActionBar might be a problem as well, but do not know how to see if that is the problem and how to fix it.

The rest of the code is mathematical calculations with a bunch of if/then/else statements and some switch statements.

The app force closes when it is opened after being installed on any OS prior to Android Pie.

Snippet from content_main.xml (layout):

<Spinner
    android:id="@+id/spnFromPool"
    android:layout_width="176dp"
    android:layout_height="34dp"
    android:layout_gravity="start"
    android:layout_weight="0.3"
    android:background="@drawable/bg_spinner"
    android:entries="@array/pool_type_array" />

bg_spinner.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/swimToolPrimary"/>
            <corners android:radius="10dp" />
            <stroke android:color="#000000" android:width="1dp" />
        </shape>
    </item>
    <item android:gravity="center_vertical|right" android:right="8dp">
        <layer-list>
            <item android:width="12dp" android:height="12dp"  android:gravity="center" android:bottom="10dp"
                tools:targetApi="m">
                <rotate
                    android:fromDegrees="45"
                    android:toDegrees="45">
                    <shape android:shape="rectangle">
                        <solid android:color="@color/swimToolSecondary" />
                        <stroke android:color="@color/swimToolSecondary" android:width="1dp"/>
                    </shape>
                </rotate>
            </item>
            <item android:width="20dp" android:height="10dp" android:bottom="21dp" android:gravity="center"
                tools:targetApi="m">
                <shape android:shape="rectangle">
                    <solid android:color="@color/swimToolPrimary"/>
                </shape>
            </item>
        </layer-list>
    </item>
</layer-list>
TonyD
  • 3
  • 3
  • When the app force close, you can get logs from LogCat in AndroidStudio. Usually, these logs contain a stack trace on which you can find the root cause of the problem. – cesarmarch Jun 14 '19 at 13:55
  • As you and @Incipientinfo have mentioned, I checked the LogCat in AndroidStudio. I found this: Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #99: Error inflating class Spinner I am guessing it is because I used a drawable. Do I need to change my layout xml file? That is where the drawable is called out. – TonyD Jun 17 '19 at 01:29

1 Answers1

1

You can check the problem in log of android studio by selecting "No Filters" in top-right corner in logcat and for filtering the data you can add package name of your app in search bar.

IncipientInfo
  • 523
  • 3
  • 10
  • @TonyD may be you have placed drawable file in wrong place. You need to place your drawable in `drawable` folder so all type of device can use that. – IncipientInfo Jun 17 '19 at 11:24
  • The drawable (it's an xml file) is in the drawable folder. When I get home I will attach my code. Now that my problem is narrowed down, I know what snippets to attach. – TonyD Jun 17 '19 at 15:19
  • @TonyD I checked our code in marshmallow and nougat devices. It worked fine for me. Afterwards, to get error I moved **bg_spinner** in drawable-v24 and got same error you are getting. So as I think you should check if **bg_spinner** is placed in **res/drawable** folder or not. – IncipientInfo Jun 18 '19 at 06:50
  • That's it. It's in the drawable-v24 folder. Ok, so all I need to do is move it to the drawable folder. So what is the difference between those two folders? And thanks a million for the help! – TonyD Jun 18 '19 at 19:31
  • Actually all different drawable folders are for different screen densities. So if you keep your drawable in **drawable-v24**, device having density different than that won't be able to get it . And the any drawable kept in **res/drawable** will be accessible by all type of devices. – IncipientInfo Jun 19 '19 at 08:30