2022-04-20 11:04:03.495 9373-9373/top.bioelectronic E/AndroidRuntime: FATAL EXCEPTION: main
Process: top.bioelectronic, PID: 9373
java.lang.RuntimeException: Unable to start activity ComponentInfo{top.bioelectronic/top.bioelectronic.ui.fragment.my.newpage.Addmachine}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
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: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:846)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:809)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at top.bioelectronic.ui.fragment.my.newpage.Addmachine.onCreate(Addmachine.java:28)
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)
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)
Addmachine页面
public class Addmachine extends AppCompatActivity implements View.OnClickListener {
private Button maddmachineBt;
private EditText machineIdEdt;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_machine);
initView();
}
private void initView(){
maddmachineBt = findViewById(R.id.add_machine_button);
machineIdEdt = findViewById(R.id.edt);
maddmachineBt.setOnClickListener(this);
machineIdEdt.setOnClickListener(this);
}
public void onClick(View view){
boolean match = false;
switch (view.getId()){
case R.id.add_machine_button:
String machineId = machineIdEdt.getText().toString().trim();
if(!TextUtils.isEmpty(machineId)){
if(machineId.length()==13){
match = true;
}else {
match = false;
}
if (match){
Toast.makeText(this,"绑定成功",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, PersonalFragment.class);
startActivity(intent);
finish();
break;
}
}else {
Toast.makeText(this,"请输入设备ID",Toast.LENGTH_SHORT).show();
}
break;
}
}
}
layout页面
<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">
<EditText
android:id="@+id/edt"
android:layout_width="254dp"
android:layout_height="63dp"
android:hint="设备ID"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteY="414dp" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="258dp"
android:layout_height="315dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.509"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.125"
app:srcCompat="@drawable/logo" />
<Button
android:id="@+id/add_machine_button"
android:layout_width="204dp"
android:layout_height="43dp"
android:background="@drawable/personal_getcode_btn"
android:backgroundTint="#fff"
android:text="添加设备"
tools:layout_editor_absoluteX="103dp"
tools:layout_editor_absoluteY="572dp"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
已在AndroidMainifest中添加Addmachine