从StationFragment启动Dashan1Activity遇ActivityNotFoundException求助
Hey there, let’s get this sorted out quick. The error you’re hitting is super straightforward—it just means your app can’t find Dashan1Activity because it’s not properly registered in your AndroidManifest.xml file. Android requires every Activity to be declared here so the system knows how to launch it.
What’s Missing
Your current manifest doesn’t have an entry for miaoli.dashan.Dashan1Activity. Let’s fix that right away.
Step-by-Step Solution
- Open your
AndroidManifest.xmlfile. - Inside the
<application>tag, add an<activity>entry forDashan1Activity. Make sure theandroid:namepoints to the correct full class path of your activity.
Here’s how your updated manifest should look (assuming your activity lives in the miaoli.dashan subpackage under your main com.coastline20 package):
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.coastline20"> <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.Coastline20"> <!-- Your existing activities go here --> <activity android:name=".MainActivity" /> <!-- Add this entry for Dashan1Activity --> <activity android:name=".miaoli.dashan.Dashan1Activity" /> </application> </manifest>
Double-Check the Class Path
Make sure the android:name matches your actual package structure:
- If
Dashan1Activityis directly in thecom.coastline20package, useandroid:name=".Dashan1Activity" - If it’s in a deeper subpackage, you can either use the shorthand (like
.miaoli.dashan.Dashan1Activity) or the full qualified name (com.coastline20.miaoli.dashan.Dashan1Activity)
Quick Check on Your Jump Code
Also, confirm your intent in StationFragment is targeting the right activity. For Java:
Intent intent = new Intent(getActivity(), Dashan1Activity.class); startActivity(intent);
For Kotlin:
val intent = Intent(requireActivity(), Dashan1Activity::class.java) startActivity(intent)
Once you add the activity entry to the manifest, Android will recognize Dashan1Activity and your jump should work as expected!
内容的提问来源于stack exchange,提问作者SpicyBoyd

