我正在登录屏幕上,它包含两个EditText,当我在android studio中运行该应用程序时,出现错误
android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class EditText
这是日志错误的第一行
E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.techgeorge.loginscreen, PID: 27960
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.techgeorge.loginscreen/org.techgeorge.loginscreen.MainActivity}: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2974)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class EditText
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class EditText
Caused by: java.lang.NumberFormatException: For input string: "18sp"
提示到xml文件的37行,它是一个EditText,但是我发现EditText没错。 xml布局文件没有给我关于任何属性错误或错字的错误。日志除了指向该行之外没有提供很多信息
setContentView(R.layout.activity_main);
MainActivity.java中的继承人的班级
package org.techgeorge.loginscreen;
public class MainActivity extends AppCompatActivity {
private TextView titleTextView, registerTextView, forgetPassTextView;
private EditText usernameEditText, passwordEditText;
private ImageView logoImageView;
private Button loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
titleTextView = findViewById(R.id.title_textview);
registerTextView = findViewById(R.id.register_textview);
forgetPassTextView = findViewById(R.id.forget_password_textview);
usernameEditText = findViewById(R.id.user_edittext);
passwordEditText = findViewById(R.id.password_edittext);
logoImageView = findViewById(R.id.logo_imageview);
loginButton = findViewById(R.id.button);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), ProfileActivity.class);
startActivity(intent);
}
});
}
}
这是xml布局类activity_main.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="@drawable/login_background"
tools:context=".MainActivity">
<ImageView
android:id="@+id/logo_imageview"
android:layout_width="62dp"
android:layout_height="61dp"
android:layout_marginTop="52dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.511"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_whatshot_white_24dp" />
<TextView
android:id="@+id/title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="@font/abril_fatface"
android:text="SUNKAT"
android:textAlignment="center"
android:textColor="@color/headerTextColor"
android:textSize="46sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo_imageview" />
<EditText
android:id="@+id/user_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="118dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#ffffff"
android:drawableLeft="@drawable/ic_person_white_24dp"
android:ems="12"
android:hint="@string/user_text_hint"
android:inputType="textPersonName"
android:text=""
android:textAlignment="center"
android:textColorHint="@color/hintTextColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_textview" />
<EditText
android:id="@+id/password_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#ffffff"
android:drawableLeft="@drawable/ic_lock_white_24dp"
android:ems="12"
android:hint="@string/password_text_hint"
android:inputType="textPassword"
android:text=""
android:textAlignment="center"
android:textColorHint="@color/hintTextColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/user_edittext" />
<Button
android:id="@+id/button"
android:layout_width="256dp"
android:layout_height="42dp"
android:layout_marginStart="8dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="8dp"
android:background="@drawable/button_shape"
android:text="login"
android:textColor="@android:color/background_light"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.539"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password_edittext" />
<TextView
android:id="@+id/register_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Register"
android:textColor="#62BCFA"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.223"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
<TextView
android:id="@+id/forget_password_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="forgot password?"
android:textColor="#62BCFA"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.762"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:1)
请注意,您的堆栈跟踪也包含以下信息:
Full match: cat
Full match: dog, cat
Full match: dog, dog, cat
Full match: dog, dog, dog
Full match: dog, dog, dog, cat
Full match: dog, dog, dog, dog, cat
Full match: dog, dog, dog, dog, dog
Full match: dog, dog, dog, dog, dog, cat
Full match: dog, dog, dog, dog, dog, dog, dog, cat
Full match: dog, dog, dog, dog, dog, dog, dog, dog, dog
这应该可以帮助您查明问题所在。
答案 1 :(得分:0)
我也经历过同样的事情,我认为它是一个错误,让我们先删除它,然后再重写