Aucune activité trouvée pour gérer l'intention {}

Nov 28 2020

Sur mon application météo , l'écran de démarrage fonctionne bien, mais lorsqu'il entre dans le HomeActivity, il s'affiche app has stopped lorsque je l'ai testé sur mon appareil

sur le logcat, il affiche:

No Activity found to handle Intent {  }

Pendant ce temps, j'ai transmis l'intention dans mon écran de démarrage:

        int SPLASH_SCREEN = 5000;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                startActivity(intent);
                finish();
            }
        }, SPLASH_SCREEN);
    }
}

Mon code HomeActivity:

public class HomeActivity extends AppCompatActivity {
    ConstraintLayout constraintLayout;
    public static int count=0;
    int[] drawable =new int[]{R.drawable.burj_khalifa,R.drawable.central_bank_of_nigeria,R.drawable.eiffel_tower,R.drawable.hong_kong,R.drawable.statue_of_liberty};
    Timer _t;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        constraintLayout = (ConstraintLayout) findViewById(R.id.layout);
        constraintLayout.setBackgroundResource(R.drawable.burj_khalifa);
            _t = new Timer();
            _t.scheduleAtFixedRate(new TimerTask() {
                @Override
                        public void run() {
                    runOnUiThread(new Runnable() { // run on ui thread
                        @Override
                        public void run() {
                            if (count < drawable.length) {

                                constraintLayout.setBackgroundResource(drawable[count]);
                                count = (count + 1) % drawable.length;
                            }
                        }
                    });
            }
        }, 5000, 5000);
    }
}

AndroidManifest.xml:

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

    <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/AppTheme">
        <activity
            android:name=".Activity.HomeActivity"
            android:label="@string/title_activity_home" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

</manifest> 

activity_home.xml:

<?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"
    android:background="@drawable/burj_khalifa"
    tools:context=".Activity.HomeActivity">


</androidx.constraintlayout.widget.ConstraintLayout>

Y a-t-il quelque chose pour corriger cela?

Réponses

3 Zain Nov 28 2020 at 22:26

Donc, retirer finish();de l'intérieur de votre gestionnaire résoudra ce problème

       new Handler().postDelayed(new Runnable() {
           @Override
           public void run() {
               Intent intent = new Intent(MainActivity.this, HomeActivity.class);
               startActivity(intent);
               finish();
           }
       }, SPLASH_SCREEN);

Si vous souhaitez supprimer l'écran de démarrage de la pile, vous pouvez faire

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Tentative d'invocation de la méthode virtuelle «void androidx.constraintlayout.widget.ConstraintLayout.setBackgroundResource (int)» sur une référence d'objet nulle

Vous êtes maintenant dans HomeActivity onCreate, et c'est différent de No Activity found to handle Intent { }Error.

cela indique que votre constraintLayoutinstruction ci-dessous est nulle et que vous ne pouvez pas l'appeler à setBackgroundResourcemoins que vous ne l'initialisiez avec une valeur non nulle

 constraintLayout.setBackgroundResource(R.drawable.burj_khalifa);

Vous l'avez obtenu à partir de la mise en page de votre activité, vous devez vérifier que cet identifiant R.id.layoutexiste réellement dans la activity_home.xmlmise en page lors de la première étape de dépannage

 constraintLayout = (ConstraintLayout) findViewById(R.id.layout);
Jamal Nov 28 2020 at 21:58

Dans votre manifeste, essayez d'écrire uniquement .HomeActivity au lieu de .Activity.HomeActivity De plus, s'il affiche toujours une erreur, je pense que vous ne pouvez pas écrire 'R.id.layout' simplement parce que 'layout' est un mot-clé alors essayez de définir un autre identifiant à votre contrainte disposition.