Logcat错误:应用程序崩溃,无法运行。根据Logcat在setContentView发生错误

团队技巧

我正在开发一个基本的方程式平衡应用程序,并且是android dev的新手。该应用程序根本无法在手机上运行。之前,我有一个启动程序启动屏幕,该屏幕曾经弹出,之后该应用程序将关闭。我删除了启动画面,现在该应用程序无法打开。我猜想MainActivity中有一个错误(用于启动它的初始屏幕,现在是启动器活动)。但是在与ADB仿真一起运行logcat时,它显示MainActivity的onCreate方法中的错误。logcat中还有更多错误,但我不知道它们的意思(我想唯一重要的错误是带有蓝色下划线的onCreate错误)。请请帮忙。

MainActivity.java

public class MainActivity extends AppCompatActivity implements DialogCloseListener {

    private RecyclerView taskRecyclerView;
    private EqBalAdapter tasksAdapter;
    private List<EqBalModel> taskList;
    private DatabaseHandler db;
    private FloatingActionButton fab;
    private FloatingActionButton fab2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActionBar bar = getActionBar();

        bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00d024")));

        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.nav_bottom);
        navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.nav_home:
                        break;
                    case R.id.nav_aboutus:
                        Intent a = new Intent(MainActivity.this, AboutUs.class);
                        startActivity(a);
                        break;
                    case R.id.nav_help:
                        Intent b = new Intent(MainActivity.this,HelpGuide.class);
                        startActivity(b);
                        break;

                }
                return false;
            }
        });


        db = new DatabaseHandler(this);
        db.openDatabase();

        taskList = new ArrayList<>();

        taskRecyclerView = findViewById(R.id.reacRecyclerView);
        taskRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        tasksAdapter = new EqBalAdapter(db, this);
        taskRecyclerView.setAdapter(tasksAdapter);

        fab = findViewById(R.id.fab);

        ItemTouchHelper itemTouchHelper = new
                ItemTouchHelper(new RecyclerItemTouchHelper(tasksAdapter));
        itemTouchHelper.attachToRecyclerView(taskRecyclerView);

        taskList = db.getAllTasks();
        Collections.reverse(taskList);
        tasksAdapter.setTasks(taskList);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AddNewTask.newInstance().show(getSupportFragmentManager(), AddNewTask.TAG);
            }
        });
        fab2=findViewById(R.id.newactivity);

        ItemTouchHelper itemTouchHelper2 = new
                ItemTouchHelper(new RecyclerItemTouchHelper(tasksAdapter));
        itemTouchHelper2.attachToRecyclerView(taskRecyclerView);


        fab2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2 = new Intent(MainActivity.this, eleView.class);
                startActivity(intent2);
            }
        });
    }

    @Override
    public void handleDialogClose(DialogInterface dialog) {
        taskList = db.getAllTasks();
        Collections.reverse(taskList);
        tasksAdapter.setTasks(taskList);
        tasksAdapter.notifyDataSetChanged();
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
        android:id="@+id/ReactantText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:text="Equation Balancer"
        android:textColor="@android:color/black"
        android:textSize="32dp"
        android:textStyle="bold" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/reacRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/ReactantText"
        android:nestedScrollingEnabled="true"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="32dp"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="32dp"
        android:layout_marginBottom="183dp"
        android:backgroundTint="@android:color/holo_green_dark"
        android:src="@drawable/ic_baseline_add" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/newactivity"
        android:layout_width="86dp"
        android:layout_height="82dp"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="56dp"
        android:layout_marginTop="56dp"
        android:layout_marginEnd="34dp"
        android:layout_marginBottom="97dp"
        android:backgroundTint="@android:color/holo_green_dark"
        android:src="@drawable/ic_baseline_elements" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/nav_bottom"
        android:layout_alignParentBottom="true"
        app:itemTextColor="@android:color/black"
        app:menu="@menu/drawer_view" />
</RelativeLayout>

AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.chemicalequationbalancer">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.ChemicalEquationBalancer">


        <activity android:name="com.example.chemicalequationbalancer.AboutUs" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
        <activity android:name="com.example.chemicalequationbalancer.HelpGuide" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
        <activity android:name="com.example.chemicalequationbalancer.eleView" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>


        <activity
            android:name="com.example.chemicalequationbalancer.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.ChemicalEquationBalancer.ActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
    </application>


</manifest>

build.gradle(app):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.chemicalequationbalancer">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.ChemicalEquationBalancer">


        <activity android:name="com.example.chemicalequationbalancer.AboutUs" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
        <activity android:name="com.example.chemicalequationbalancer.HelpGuide" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
        <activity android:name="com.example.chemicalequationbalancer.eleView" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>


        <activity
            android:name="com.example.chemicalequationbalancer.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.ChemicalEquationBalancer.ActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
    </application>


</manifest>

Logcat这是logcat中带下划线的行:com.example.chemicalequationbalancer.MainActivity.onCreate(MainActivity.java:51)

2021-02-16 02:07:50.712 13502-13502/com.example.chemicalequationbalancer E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.chemicalequationbalancer, PID: 13502
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chemicalequationbalancer/com.example.chemicalequationbalancer.MainActivity}: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3197)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3334)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2025)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:226)
        at android.app.ActivityThread.main(ActivityThread.java:7191)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:499)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
     Caused by: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
     Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:652)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:817)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:740)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:890)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:851)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at com.android.internal.policy.DecorView.onResourcesLoaded(DecorView.java:2239)
        at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2761)
        at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2868)
        at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2133)
        at androidx.appcompat.app.AppCompatActivity.initViewTreeOwners(AppCompatActivity.java:198)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:173)
        at **com.example.chemicalequationbalancer.MainActivity.onCreate(MainActivity.java:51)**
        at android.app.Activity.performCreate(Activity.java:7376)
        at android.app.Activity.performCreate(Activity.java:7367)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3177)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3334)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2025)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:226)
        at android.app.ActivityThread.main(ActivityThread.java:7191)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:499)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
2021-02-16 02:07:50.714 13502-13502/com.example.chemicalequationbalancer E/AndroidRuntime: Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x1010433 a=1}
        at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
        at android.view.View.<init>(View.java:5108)
        at android.view.ViewGroup.<init>(ViewGroup.java:665)
        at android.widget.FrameLayout.<init>(FrameLayout.java:92)
        at android.widget.FrameLayout.<init>(FrameLayout.java:87)
        at android.widget.FrameLayout.<init>(FrameLayout.java:82)
        at com.android.internal.widget.ActionBarContainer.<init>(ActionBarContainer.java:61)
            ... 32 more

如果需要其他文件,我准备提供。我只想知道发生了什么,并进行解决。谢谢!

PS:这些文件夹中的哪一个实际上可以转换为apk?是主文件夹,即化学平衡仪吗?

编辑:themes.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.ChemicalEquationBalancer" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@android:color/transparent</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>

    <style name="Theme.ChemicalEquationBalancer.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="Theme.ChemicalEquationBalancer.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="Theme.ChemicalEquationBalancer.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="windowActionBar">true</item>
        <item name="windowNoTitle">false</item>
    </style>

    <style name="Theme.ChemicalEquationBalancer.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
    <style name="DialogStyle" parent="Theme.Design.BottomSheetDialog">
        <item name="android:windowIsFloating">false</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowSoftInputMode">adjustResize</item>
    </style>

</resources>
莎拉·汗(Sarah Khan)

您的MainActivity正在扩展AppCompatActivity,这意味着它继承了默认操作栏。

ThemeOverlay.AppCompat(Theme.ChemicalEquationBalancer.ActionBar的父级)用于针对特定视图(尤其是工具栏)覆盖(或“覆盖”)该主题。

如果要自定义此ActionBar(您可能正在这样做),请在活动清单中添加NoActionBar主题之一,然后在活动布局中提供工具栏。

    <activity
        android:name="com.example.chemicalequationbalancer.MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.Light.NoActionBar" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

在activity_main.xml中,您可以添加所需的任何主题

<androidx.appcompat.widget.Toolbar
    ...
    android:background="?attr/colorPrimary"
    android:theme="@style/Theme.ChemicalEquationBalancer.ActionBar />

而且不在清单文件中

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android 应用程序崩溃,没有 logcat 错误

来自分类Dev

android studio 中的 LogCat 错误,运行时应用程序崩溃

来自分类Dev

LogCat错误停止应用程序运行-添加代码

来自分类Dev

我的GoogleMap应用程序无法运行,但logcat中没有错误

来自分类Dev

运行时强制关闭应用程序,LogCat 致命异常错误导致类 RecyclerView 膨胀

来自分类Dev

Android第一个应用程序Hello World Logcat错误

来自分类Dev

即使应用程序工作正常,我在 logcat 中也收到错误消息?

来自分类Dev

我的应用停止了logcat错误

来自分类Dev

在Android Studio中运行应用程序时发生错误

来自分类Dev

代码没有错误,logcat 什么都没有,但不幸的是应用程序停止了错误

来自分类Dev

无法应用类DataAdapter中的Logcat错误构造函数DataAdapter

来自分类Dev

注册结束时发生Logcat错误

来自分类Dev

运行命令遇到内部错误:错误:启动应用程序时发生错误

来自分类Dev

尝试从github实现CountryPicker。代码中没有错误,应用崩溃,很多logcat错误

来自分类Dev

Android setContentView使我的应用程序崩溃

来自分类Dev

发布应用程序后的Logcat

来自分类Dev

Logcat 显示我为我的 Android 应用程序创建的 SQLite 数据库的各种类型的错误

来自分类Dev

Android Studio + AVD:应用程序在模拟器中崩溃,logcat为空

来自分类Dev

Ubuntu上的Grails无法运行应用程序。摇篮错误

来自分类Dev

应用程序无法运行,但编译没有错误

来自分类Dev

启动应用程序时发生错误

来自分类Dev

jsonarray无法转换为jsonobject logcat错误

来自分类Dev

jsonarray无法转换为jsonobject logcat错误

来自分类Dev

运行Spring Session + Spring Boot应用程序时发生运行时错误

来自分类Dev

Unity Firebase Crashlytics未发送任何崩溃报告,logcat上出现“无法检索设置”错误

来自分类Dev

将应用程序安装到设备Xcode 11.6时无法运行应用程序错误

来自分类Dev

Logcat无法检测到应用程序或程序包名称

来自分类Dev

LogCat,其中我的SQLite语句为红色,但应用程序运行正常

来自分类Dev

Android应用程序甚至无法运行。Logcat显示“无法将android.widget.text视图强制转换为android.widget.Button”。

Related 相关文章

  1. 1

    Android 应用程序崩溃,没有 logcat 错误

  2. 2

    android studio 中的 LogCat 错误,运行时应用程序崩溃

  3. 3

    LogCat错误停止应用程序运行-添加代码

  4. 4

    我的GoogleMap应用程序无法运行,但logcat中没有错误

  5. 5

    运行时强制关闭应用程序,LogCat 致命异常错误导致类 RecyclerView 膨胀

  6. 6

    Android第一个应用程序Hello World Logcat错误

  7. 7

    即使应用程序工作正常,我在 logcat 中也收到错误消息?

  8. 8

    我的应用停止了logcat错误

  9. 9

    在Android Studio中运行应用程序时发生错误

  10. 10

    代码没有错误,logcat 什么都没有,但不幸的是应用程序停止了错误

  11. 11

    无法应用类DataAdapter中的Logcat错误构造函数DataAdapter

  12. 12

    注册结束时发生Logcat错误

  13. 13

    运行命令遇到内部错误:错误:启动应用程序时发生错误

  14. 14

    尝试从github实现CountryPicker。代码中没有错误,应用崩溃,很多logcat错误

  15. 15

    Android setContentView使我的应用程序崩溃

  16. 16

    发布应用程序后的Logcat

  17. 17

    Logcat 显示我为我的 Android 应用程序创建的 SQLite 数据库的各种类型的错误

  18. 18

    Android Studio + AVD:应用程序在模拟器中崩溃,logcat为空

  19. 19

    Ubuntu上的Grails无法运行应用程序。摇篮错误

  20. 20

    应用程序无法运行,但编译没有错误

  21. 21

    启动应用程序时发生错误

  22. 22

    jsonarray无法转换为jsonobject logcat错误

  23. 23

    jsonarray无法转换为jsonobject logcat错误

  24. 24

    运行Spring Session + Spring Boot应用程序时发生运行时错误

  25. 25

    Unity Firebase Crashlytics未发送任何崩溃报告,logcat上出现“无法检索设置”错误

  26. 26

    将应用程序安装到设备Xcode 11.6时无法运行应用程序错误

  27. 27

    Logcat无法检测到应用程序或程序包名称

  28. 28

    LogCat,其中我的SQLite语句为红色,但应用程序运行正常

  29. 29

    Android应用程序甚至无法运行。Logcat显示“无法将android.widget.text视图强制转换为android.widget.Button”。

热门标签

归档