When I run my app in the android emulator, my app keeps stopping. How can I resolve this?

Viewed 148

All my files have no errors! But then also in LOGCAT after the app crashes an error pointing to my MainActivity.kt file is present. Once I click on it, it points to -> setContentView(R.layout.activity_main).

One more thing. When I click on the LOGCAT thing it says "sources for android api 32 not found" and above it, it says " decompile .class file, bytecode version 52.0(java 8) ".

Just to let you know that, I have only build my layout whereas I was going to build the MainActicity.kt file later.

I was assuming it is because of api or sdk mismatch or maybe some syntax in my xml which is not imported or something like that.

ERROR ->

2022-01-04 23:58:05.977 3507-3507/com.example.trail E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.trail, PID: 3507
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.trail/com.example.trail.MainActivity}: android.view.InflateException: Binary XML file line #49 in com.example.trail:layout/activity_main: Binary XML file line #49 in com.example.trail:layout/activity_main: Error inflating class Button
        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 #49 in com.example.trail:layout/activity_main: Binary XML file line #49 in com.example.trail:layout/activity_main: Error inflating class Button
     Caused by: android.view.InflateException: Binary XML file line #49 in com.example.trail:layout/activity_main: Error inflating class Button
     Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 14 to dimension: type=0x10
        at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:787)
        at android.view.View.<init>(View.java:5538)
        at android.widget.TextView.<init>(TextView.java:996)
        at android.widget.Button.<init>(Button.java:166)
        at android.widget.Button.<init>(Button.java:141)
        at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:80)
        at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:224)
        at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:220)
        at com.google.android.material.theme.MaterialComponentsViewInflater.createButton(MaterialComponentsViewInflater.java:43)
        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:129)
        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1566)
        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1617)
        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1059)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995)
        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.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 android.view.LayoutInflater.inflate(LayoutInflater.java:479)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:706)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
        at com.example.trail.MainActivity.onCreate(MainActivity.kt:9)
        at android.app.Activity.performCreate(Activity.java:7994)
        at android.app.Activity.performCreate(Activity.java:7978)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
2022-01-04 23:58:05.977 3507-3507/com.example.trail E/AndroidRuntime:     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)

BUTTON [ I was building a calculator and was trying for rounded buttons. When I did that it removed the boundaries too :(. I think I have imported something wrong maybe I am using some wrong import?]->

            <Button
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@integer/margin"
                android:padding="@integer/padding"
                android:text="@string/divide"
                android:textColor="@color/THEME1"
                android:textSize="35sp"
                app:cornerRadius="10dp" />

How it looks right now -> enter image description here

1 Answers
android:layout_margin="@integer/margin"
android:padding="@integer/padding"

Use a dimen resource for margins and paddings. Raw number such as integer cannot be used as a dimension that also requires a unit such as dp.

Related