1. 程式人生 > >Error running app:Default Activity not found 解決方法

Error running app:Default Activity not found 解決方法

問題顯示  Error running app:Default Activity not found

此時你會發現執行不了,這是因為在AndroidManifest.xml檔案中,我們只是註冊了活動,並沒有為程式配置主活動(當程式執行的時候,不知道先啟動那個活動),所以只要新增幾行程式碼即可。在<activity>標籤里加入<intent-filter>標籤即可

 <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=".FirstActivity" android:label="This is FirstActivity"> <intent-filter> <action android:name="
android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application>

然後問題解決,初學者很容易犯的錯誤,尤其是在一開始就選定了add no activity 的時候,Android studio是不會幫助我們自行配置好的,需要手動配置