2017-02-26 170 views
2

我在啓動我的應用程序時遇到問題,因爲它向我提供了「未找到默認活動」錯誤。我已閱讀其他線程,並嘗試添加/更改以下代碼的位置:未找到默認活動錯誤Android Studio

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

但它仍然不起作用。我也試過

File -> Invalidate Caches/Restart... 

仍然不起作用。以下是我的Android Manifest.xml文件。我想用名爲「.Main2Activity」的活動啓動我的應用程序。另外請注意,出於某種原因,設計模式下的.xml文件顯示爲黑色背景,並且有些奇怪。

<?xml version="1.0" encoding="utf-8"?> 

<!-- 
    The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
    Google Maps Android API v2, but you must specify either coarse or fine 
    location permissions for the 'MyLocation' functionality. 
--> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    <uses-feature 
     android:name="android.hardware.camera" 
     android:required="true" /> 

    <activity android:name=".MainActivity" /> 
    </activity> 


    <activity android:name=".Dining" /> 
    <activity android:name=".SignUp" /> 

    <provider 
     android:name="android.s 


     upport.v4.content.FileProvider" 
     android:authorities="com.example.android.fileprovider" 
     android:exported="false" 
     android:grantUriPermissions="true"> 
     <meta-data 
      android:name="android.support.FILE_PROVIDER_PATHS" 
      android:resource="@layout/file_paths" /> 
    </provider> 
    <!-- 
     The API key for Google Maps-based APIs is defined as a string resource. 
     (See the file "res/values/google_maps_api.xml"). 
     Note that the API key is linked to the encryption key used to sign the APK. 
     You need a different API key for each encryption key, including the release key that is used to 
     sign the APK for publishing. 
     You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    --> 
    <meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="AIzaSyD37TQWZ02Re5_3lTH-kL17cOOVQw1B8dY" /> 

    <activity> 
     android:name=".MapsActivity" 
     android:label="@string/title_activity_maps" /> 


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

    <activity android:name=".MapsMain"></activity> 
</application> 

回答

2
<activity> 
     android:name=".MapsActivity" 
     android:label="@string/title_activity_maps" /> 

檢查, 你必須在XML該錯誤。 這將是:

<activity 
     android:name=".MapsActivity" 
     android:label="@string/title_activity_maps" /> 

是不是?

0

你有沒有嘗試過這樣的:https://stackoverflow.com/a/22028681/1101730.

這些行添加到文件的build.gradle Android的{...}塊中:

的Android { ... sourceSets { main.java .srcDirs + ='src/main /' } }

編輯文件後,單擊工具> Android>使用Gradle文件同步項目。

我能想到的最後一件事是點擊運行>編輯配置,並確保您的活動被選定爲啓動活動。

相關問題