Search code examples
androidandroid-intentandroid-activityandroid-studiostart-activity

Cannot Start an Activity - Android


My Android Studio is autocompleting my code and it's going wrong. What I'm trying to do is:

Intent intent = new Intent(getActivity(), DetailActivity.class);
startActivity(intent);

But it aways becomes:

Intent intent = new Intent(getActivity(), com.example.android.sunshine.app.DetailActivity.class);
startActivity(intent);

And there's an error on the word "sunshine" that make it get red. If I try to build I get this:

Error:(97, 87) error: cannot find symbol class app<br>

I already saw other codes and they all work fine with the first code. What should I do?

Here is my AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.com.example.android.sunshine" >

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

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".DetailActivity"
        android:label="@string/title_activity_detail"
        android:parentActivityName=".MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="app.com.example.android.sunshine.MainActivity" />
    </activity>
</application>

The Activity name (DetailActivity) in this line, is also red:

 android:name=".DetailActivity"

Solution

  • In your second activity <meta-data> you have

    android:value="app.com.example.android.sunshine.MainActivity"
    

    Should probably be

    android:value="com.example.android.sunshine.app.MainActivity"
    

    And if the red marking on the sunshine word bothers you, hover your cursor over it and see what the Studio complains about -- probably just suspecting you misspelled sun shine (which you obviously didn't)