My dream? 2022-04-20 11:21 采纳率: 50%
浏览 245
已结题

安卓跳转页面时发生闪退

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

  • 写回答

2条回答 默认 最新

  • weixin_42120514 2022-04-20 16:26
    关注

    Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    看Caused by这一行就是报错的原因
    这个报错是AndroidMainifest中没有设置全局的theme,也没有对 Addmachine设置theme

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月28日
  • 已采纳回答 4月20日
  • 创建了问题 4月20日

悬赏问题

  • ¥18 深度学习tensorflow1,ssdv1,coco数据集训练一个模型
  • ¥100 关于注册表摄像头和麦克风的问题
  • ¥30 代码本地运行正常,但是TOMCAT部署时闪退
  • ¥15 关于#python#的问题
  • ¥15 主机可以ping通路由器但是连不上网怎么办
  • ¥15 数据库一张以时间排好序的表中,找出多次相邻的那些行
  • ¥50 关于DynamoRIO处理多线程程序时候的问题
  • ¥15 kubeadm部署k8s出错
  • ¥15 Abaqus打不开cae文件怎么办?
  • ¥15 小程序准备上线,软件开发公司需要提供哪些资料给甲方