如果我尝试通过模拟器运行我的应用程序,它将继续停止..我该如何修复? 这是我的日志猫:
2019-11-27 19:51:23.289 9621-9621/com.e.xmasplan E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.e.xmasplan, PID: 9621
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.e.xmasplan/com.e.xmasplan.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
原因:java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代)。
at com.e.xmasplan.MainActivity.onCreate(MainActivity.java:35) this line is blue printed.
这是第35行:userEmail = findViewById(R.id.email); xml文件中的ID为电子邮件
这是mainactivity xml文件:
`enter code here`<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<EditText
android:id="@+id/username"
android:layout_width="200dp"
android:layout_height="55dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Username"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.578"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.193" />
<EditText
android:id="@+id/email"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_marginBottom="380dp"
android:ems="10"
android:inputType="textEmailAddress"
android:text="E-Mail"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.578"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username"
app:layout_constraintVertical_bias="0.109" />
<EditText
android:id="@+id/pw"
android:layout_width="200dp"
android:layout_height="55dp"
android:ems="10"
android:inputType="textPassword"
android:text="Password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.578"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/email"
app:layout_constraintVertical_bias="0.029"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/pw2"
android:layout_width="200dp"
android:layout_height="55dp"
android:ems="10"
android:inputType="textPassword"
android:text="Confirm Password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.578"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pw"
app:layout_constraintVertical_bias="0.037"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/regbtn"
android:layout_width="167dp"
android:layout_height="51dp"
android:text="Register"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.577"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pw2"
app:layout_constraintVertical_bias="0.355" />
<ProgressBar
android:id="@+id/regProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="64dp"
android:layout_height="44dp"
app:layout_constraintBottom_toBottomOf="@+id/regbtn"
app:layout_constraintEnd_toEndOf="@+id/regbtn"
app:layout_constraintHorizontal_bias="0.514"
app:layout_constraintStart_toStartOf="@+id/regbtn"
app:layout_constraintTop_toTopOf="@+id/regbtn"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/signin"
android:layout_width="311dp"
android:layout_height="45dp"
android:text="Already have an account ? Sign in here"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.638"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/regbtn"
app:layout_constraintVertical_bias="0.45" />
</androidx.constraintlayout.widget.ConstraintLayout>
答案 0 :(得分:3)
按照以下步骤修改Main Activity
中的Manifest
标记
<activity android:name=".MainActivity"
android:theme="@style/Theme.AppCompat" >
答案 1 :(得分:0)
转到您的MainActivity的xml并选择另一个主题,该主题位于您要在其上模拟代码的设备的模拟权限下方,选择了应用主题或某种浅色主题