Я пишу код для приложения, которое представляет собой калькулятор чаевых, который будет использоваться для расчета чаевых и разделения счета. Мое приложение работает без ошибок, но продолжает сбой. Вскоре после получения уведомления «Системный интерфейс не отвечает».
- вот мой MainActivity. java:
package com.personal.tipcalculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.split_bill);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openSplitBill();
}
});
}
public void openSplitBill() {
Intent intent = new Intent(this, SplitBill.class);
startActivity(intent);
button = findViewById(R.id.calculate_tip);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openCalculateTip();
}
});
}
public void openCalculateTip () {
Intent intent = new Intent(this, CalculateTip.class);
startActivity(intent);
}
}
здесь моя активность_основная. xml
<RelativeLayout 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="@android:color/background_dark"
tools:context="com.personal.tipcalculator.MainActivity">
<Button
android:id="@+id/calculate_tip"
style="@android:style/Widget.Material.Button.Borderless.Colored"
android:layout_width="307dp"
android:layout_height="122dp"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="51dp"
android:text="@string/calculatetip"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="#03A9F4"
android:textSize="40sp"
android:textStyle="bold" />
<Button
android:id="@+id/split_bill"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="307dp"
android:layout_height="122dp"
android:layout_below="@+id/calculate_tip"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="46dp"
android:layout_marginTop="77dp"
android:layout_marginEnd="58dp"
android:layout_marginBottom="127dp"
android:backgroundTint="#000000"
android:paddingTop="@android:dimen/dialog_min_width_major"
android:text="@string/splitbill"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="#03A9F4"
android:textSize="40sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/iv_logo"
android:layout_width="match_parent"
android:layout_height="238dp"
android:layout_above="@+id/calculate_tip"
android:layout_marginBottom="44dp"
app:srcCompat="@mipmap/logo"
android:contentDescription="@string/todo" />
</RelativeLayout>
Я решил, что ошибка должна быть в основном коде активности, вот и все, что я написал.
Вот мой LogCat:
2020-04-18 09:27:12.660 6603-6603/com.personal.tipcalculator E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.personal.tipcalculator, PID: 6603
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.personal.tipcalculator/com.personal.tipcalculator.MainActivity}: android.view.InflateException: Binary XML file line #25 in com.personal.tipcalculator:layout/activity_main: Binary XML file line #25 in com.personal.tipcalculator:layout/activity_main: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #25 in com.personal.tipcalculator:layout/activity_main: Binary XML file line #25 in com.personal.tipcalculator:layout/activity_main: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #25 in com.personal.tipcalculator:layout/activity_main: Error inflating class Button
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 16 to dimension: type=0x6
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:786)
at android.view.View.<init>(View.java:5279)
at android.widget.TextView.<init>(TextView.java:974)
at android.widget.Button.<init>(Button.java:166)
at android.widget.Button.<init>(Button.java:141)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:71)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:67)
at androidx.appcompat.app.AppCompatViewInflater.createButton(AppCompatViewInflater.java:187)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:110)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1061)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.personal.tipcalculator.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)