“无法启动活动ComponentInfo”错误

时间:2018-08-26 23:44:23

标签: java android

大家好,我对标题错误有疑问。我不知道发生了什么,几秒钟之后一切都会正常进行...崩溃之前,我唯一要做的就是将ACTIVITY MAIN.xml的“项目”尺寸从准确的更改为“匹配约束”,但是当我发现应用程序崩溃了,我撤消了所有修改,至少我相信如此……有人可以帮助我吗? 对不起,如果我不太准确,如果您想了解更多信息,请告诉我! 谢谢大家!

主要

    package com.example.principale.gapgo;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {



    //Cosa succede quando viene creata l'activity
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        //Creo progressBar

        final ProgressBar carica = (ProgressBar) findViewById(R.id.progressBarCarica);



        //Creo Bottone

        final Button on = (Button) findViewById(R.id.buttonOnBianco);
        on.setVisibility(View.INVISIBLE);



        //Creo ImageView

        final ImageView onNero = (ImageView) findViewById(R.id.imageViewOnNero);
        onNero.setVisibility(View.INVISIBLE);



        //Metodo che aspetta tot secondi prima di entrare nel menu
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                try {
                    //Setto visibilità componenti
                    carica.setVisibility(View.INVISIBLE);
                    on.setVisibility(View.VISIBLE);
                    onNero.setVisibility(View.VISIBLE);
                    on.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //Setto visibilità bottone on
                            on.setVisibility(View.INVISIBLE);
                            //Aspetto
                            Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                public void run() {
                                    try {
                                        //Setto visibilità bottone on
                                        on.setVisibility(View.VISIBLE);
                                        //Apro il menu
                                        openActivityMenu();
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, 5);   //5 millisecondi di attesa
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, 3000);   //3 secondi di attesa



    //fine onCreate
    }



    //Cosa succede quando viene premuto il bottone back
    @Override
    public void onBackPressed() {
        System.exit(0);
    }



    //Lista di Intent per cambiare Activity

    public void openActivityMenu() {
        Intent intent = new Intent(getApplicationContext(), Menu.class);
        startActivity(intent);
    }
}

主要活动

<?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="@color/arancio"
    android:backgroundTint="@color/arancio"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageViewLogo"
        android:layout_width="285dp"
        android:layout_height="285dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:adjustViewBounds="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/logo_bianco" />

    <TextView
        android:id="@+id/textViewGap"
        android:layout_width="145dp"
        android:layout_height="45dp"
        android:layout_marginTop="24dp"
        android:fontFamily="monospace"
        android:text="@string/logo_name"
        android:textAlignment="center"
        android:textColor="@color/bianco"
        android:textSize="36sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageViewLogo" />

    <ProgressBar
        android:id="@+id/progressBarCarica"
        style="?android:progressBarStyleHorizontal"
        android:layout_width="115dp"
        android:layout_height="74dp"
        android:layout_marginTop="32dp"
        android:indeterminate="true"
        android:max="100"
        android:progress="2"
        android:visibility="visible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewGap" />

    <Button
        android:id="@+id/buttonOnBianco"
        android:layout_width="115dp"
        android:layout_height="115dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:background="@mipmap/on_off"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewGap" />

    <ImageView
        android:id="@+id/imageViewOnNero"
        android:layout_width="115dp"
        android:layout_height="115dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewGap"
        app:srcCompat="@mipmap/on_off_nero" />

</android.support.constraint.ConstraintLayout>

菜单

package com.example.principale.gapgo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Menu extends AppCompatActivity {

    //Cosa succede quando viene creata l'actvity
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);



        //Set dei vari bottoni - INIZIO

        Button disponibilita = (Button) findViewById(R.id.buttonDisponibilità);
        disponibilita.setOnClickListener(new View.OnClickListener() {
            @Override
            //Cosa succede quando premo il bottone sopra menzionato
            public void onClick(View v) {
                openActivityDisponibilita();
            }
        });

        Button riunioni = (Button) findViewById(R.id.buttonRiunioni);
        riunioni.setOnClickListener(new View.OnClickListener() {
            @Override
            //Cosa succede quando premo il bottone sopra menzionato
            public void onClick(View v) {
                openActivityRiunioni();
            }
        });

        Button doveri = (Button) findViewById(R.id.buttonDoveri);
        doveri.setOnClickListener(new View.OnClickListener() {
            @Override
            //Cosa succede quando premo il bottone sopra menzionato
            public void onClick(View v) {
                openActivityDoveri();
            }
        });

        Button documenti = (Button) findViewById(R.id.buttonDocumenti);
        documenti.setOnClickListener(new View.OnClickListener() {
            @Override
            //Cosa succede quando premo il bottone sopra menzionato
            public void onClick(View v) {
                openActivityDocumenti();
            }
        });

        Button materiali = (Button) findViewById(R.id.buttonMateriali);
        materiali.setOnClickListener(new View.OnClickListener() {
            @Override
            //Cosa succede quando premo il bottone sopra menzionato
            public void onClick(View v) {
                openActivityMateriali();
            }
        });

        //Set dei vari bottoni - FINE

    //Fine onCreate
    }



    //Cosa succede quando premo back
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        try {
            //Apro l'activity sotto specificata
            openActivityMain();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    //Lista di intent per nuove Activiti - INIZIO

    public void openActivityMain() {
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(intent);
    }

    public void openActivityDisponibilita() {
        Intent intent = new Intent (getApplicationContext(), Disponibilita.class);
        startActivity(intent);
    }

    public void openActivityDocumenti() {
        Intent intent = new Intent (getApplicationContext(), Documenti.class);
        startActivity(intent);
    }

    public void openActivityMateriali() {
        Intent intent = new Intent (getApplicationContext(), Materiali.class);
        startActivity(intent);
    }

    public void openActivityRiunioni() {
        Intent intent = new Intent (getApplicationContext(), Riunioni.class);
        startActivity(intent);
    }

    public void openActivityDoveri() {
        Intent intent = new Intent (getApplicationContext(), Doveri.class);
        startActivity(intent);
    }

    //Lista di intent per nuove Activiti - FINE
}

活动菜单

<?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="@color/arancio"
    tools:context=".Menu">

    <TextView
        android:id="@+id/textViewStagione"
        android:layout_width="177dp"
        android:layout_height="77dp"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="68dp"
        android:fontFamily="monospace"
        android:text="@string/stragione"
        android:textAlignment="center"
        android:textColor="@color/bianco"
        android:textSize="30sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/buttonDisponibilità"
        style="@android:style/Widget.Holo.Button.Small"
        android:layout_width="350dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="216dp"
        android:background="@color/bianco"
        android:elevation="0dp"
        android:fontFamily="monospace"
        android:text="@string/disponibilita"
        android:textAlignment="center"
        android:textAppearance="@android:style/TextAppearance.Material.Medium"
        android:textColor="@color/arancio"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/buttonDocumenti"
        style="@android:style/Widget.Holo.Button.Small"
        android:layout_width="350dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:background="@color/bianco"
        android:text="@string/documenti"
        android:textAlignment="center"
        android:textColor="@color/arancio"
        android:textSize="18sp"
        android:textStyle="bold"
        android:typeface="monospace"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonDoveri" />

    <Button
        android:id="@+id/buttonMateriali"
        style="@android:style/Widget.Holo.Button.Small"
        android:layout_width="350dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:background="@color/bianco"
        android:fontFamily="monospace"
        android:text="@string/materiali"
        android:textAlignment="center"
        android:textColor="@color/arancio"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonDocumenti" />

    <Button
        android:id="@+id/buttonRiunioni"
        style="@android:style/Widget.Holo.Button.Borderless.Small"
        android:layout_width="350dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:background="@color/bianco"
        android:fontFamily="monospace"
        android:text="@string/riunioni"
        android:textAlignment="center"
        android:textColor="@color/arancio"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonDisponibilità" />

    <Button
        android:id="@+id/buttonDoveri"
        style="@android:style/Widget.Holo.Button.Borderless.Small"
        android:layout_width="350dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:background="@color/bianco"
        android:fontFamily="monospace"
        android:text="@string/doveri"
        android:textAlignment="center"
        android:textColor="@color/arancio"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonRiunioni" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="209dp"
        android:layout_height="198dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/logo_bianco" />

</android.support.constraint.ConstraintLayout>

清单

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

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/logo_bianco"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/logo_cia_standard"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Menu" />
        <activity android:name=".Disponibilita" />
        <activity android:name=".Documenti" />
        <activity android:name=".Materiali" />
        <activity android:name=".Riunioni" />
        <activity android:name=".Doveri"></activity>
    </application>

</manifest>

LOGCAT

08-27 01:31:22.646 25670-25670/com.example.principale.gapgo D/HwRTBlurUtils: check blur style for HwPhoneWindow, themeResId : 0x7f0d0006, context : com.example.principale.gapgo.MainActivity@835f2b, Nhwext : 0, get Blur : disable with , null
08-27 01:31:22.647 25670-25670/com.example.principale.gapgo D/HwRTBlurUtils: check blur style for HwPhoneWindow, themeResId : 0x7f0d0006, context : com.example.principale.gapgo.MainActivity@835f2b, Nhwext : 0, get Blur : disable with , null
08-27 01:31:22.651 25670-25670/com.example.principale.gapgo W/ResourceType: For resource 0x7f09001b, entry index(27) is beyond type entryCount(10)
    Failure getting entry for 0x7f09001b (t=8 e=27) (error -75)
08-27 01:31:22.652 25670-25670/com.example.principale.gapgo D/AndroidRuntime: Shutting down VM
08-27 01:31:22.657 25670-25670/com.example.principale.gapgo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.principale.gapgo, PID: 25670
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.principale.gapgo/com.example.principale.gapgo.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001b
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
        at android.app.ActivityThread.-wrap12(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7425)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001b
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:279)
        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2310)
        at android.content.res.Resources.getLayout(Resources.java:1293)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
        at com.example.principale.gapgo.MainActivity.onCreate(MainActivity.kt:11)
        at android.app.Activity.performCreate(Activity.java:7372)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302) 
        at android.app.ActivityThread.-wrap12(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891) 
        at android.os.Handler.dispatchMessage(Handler.java:108) 
        at android.os.Looper.loop(Looper.java:166) 
        at android.app.ActivityThread.main(ActivityThread.java:7425) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 
08-27 01:31:22.793 25670-25670/com.example.principale.gapgo I/Process: Sending signal. PID: 25670 SIG: 9

代码可以编译,但是当我尝试午餐时,应用程序崩溃了!!

2 个答案:

答案 0 :(得分:1)

请注意,错误是“找不到资源”。

  

08-27 01:31:22.657 25670-25670 / com.example.principale.gapgo E / AndroidRuntime:FATAL EXCEPTION:main       流程:com.example.principale.gapgo,PID:25670       java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.principale.gapgo / com.example.principale.gapgo.MainActivity}:android.content.res.Resources $ NotFoundException:资源ID#0x7f09001b

由于资源ID看起来不是 ASCII 字符串,因此下面的行看起来有些问题。

Button disponibilita = (Button) findViewById(R.id.buttonDisponibilità);

还要检查引用不存在的资源ID的行。

其他相关信息是通过在android.enableAapt2内的下面一行添加https://stackoverflow.com/a/45965816/8034839

来禁用gradle.properties
android.enableAapt2=false

答案 1 :(得分:0)

可能是

错误
<Button
        android:id="@+id/buttonDisponibilità"
        style="@android:style/Widget.Holo.Button.Small"
        android:layout_width="350dp"
        android:layout_height="35dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="216dp"
        android:background="@color/bianco"
        android:elevation="0dp"
        android:fontFamily="monospace"
        android:text="@string/disponibilita"
        android:textAlignment="center"
        android:textAppearance="@android:style/TextAppearance.Material.Medium"
        android:textColor="@color/arancio"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
  

替换为

<Button
    android:id="@+id/buttonDisponibilita"
    style="@android:style/Widget.Holo.Button.Small"
    android:layout_width="350dp"
    android:layout_height="35dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="216dp"
    android:background="@color/bianco"
    android:elevation="0dp"
    android:fontFamily="monospace"
    android:text="@string/disponibilita"
    android:textAlignment="center"
    android:textAppearance="@android:style/TextAppearance.Material.Medium"
    android:textColor="@color/arancio"
    android:textStyle="bold"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />