Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

app crashes when clicking back button.

My ribbit app crashes when I click the back button. I changed the name in my app to Textly. I've followed everything else the same way as the videos. This is what I'm getting in my logcat:

05-02 07:12:41.329: E/NavUtils(8934): getParentActivityIntent: bad parentActivityName 'com.jordanpeterson.textly.MainActivity' in manifest 05-02 07:12:41.329: W/dalvikvm(8934): threadid=1: thread exiting with uncaught exception (group=0x40aaf1f8) 05-02 07:12:41.329: E/AndroidRuntime(8934): FATAL EXCEPTION: main 05-02 07:12:41.329: E/AndroidRuntime(8934): java.lang.IllegalArgumentException: Activity ViewImageActivity does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data> element in your manifest?) 05-02 07:12:41.329: E/AndroidRuntime(8934): at android.support.v4.app.NavUtils.navigateUpFromSameTask(NavUtils.java:178) 05-02 07:12:41.329: E/AndroidRuntime(8934): at com.jordanpeterson.textly.ui.ViewImageActivity.onOptionsItemSelected(ViewImageActivity.java:50) 05-02 07:12:41.329: E/AndroidRuntime(8934): at android.app.Activity.onMenuItemSelected(Activity.java:2508) 05-02 07:12:41.329: E/AndroidRuntime(8934): at com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:166) 05-02 07:12:41.329: E/AndroidRuntime(8934): at android.view.View.performClick(View.java:3511) 05-02 07:12:41.329: E/AndroidRuntime(8934): at android.view.View$PerformClick.run(View.java:14111) 05-02 07:12:41.329: E/AndroidRuntime(8934): at android.os.Handler.handleCallback(Handler.java:605) 05-02 07:12:41.329: E/AndroidRuntime(8934): at android.os.Handler.dispatchMessage(Handler.java:92) 05-02 07:12:41.329: E/AndroidRuntime(8934): at android.os.Looper.loop(Looper.java:137) 05-02 07:12:41.329: E/AndroidRuntime(8934): at android.app.ActivityThread.main(ActivityThread.java:4429) 05-02 07:12:41.329: E/AndroidRuntime(8934): at java.lang.reflect.Method.invokeNative(Native Method) 05-02 07:12:41.329: E/AndroidRuntime(8934): at java.lang.reflect.Method.invoke(Method.java:511) 05-02 07:12:41.329: E/AndroidRuntime(8934): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:3151) 05-02 07:12:41.329: E/AndroidRuntime(8934): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:2918) 05-02 07:12:41.329: E/AndroidRuntime(8934): at dalvik.system.NativeStart.main(Native Method)

This is my manifest file:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jordanpeterson.textly" android:versionCode="1" android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />

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

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

- <application android:name="com.jordanpeterson.textly.TextlyApplication" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name"

android:theme="@style/Theme.Textly" >

    <activity
        android:name="com.jordanpeterson.textly.ui.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.jordanpeterson.textly.ui.LoginActivity"
        android:label="@string/title_activity_login"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name="com.jordanpeterson.textly.ui.SignUpActivity"
        android:label="@string/title_activity_sign_up"
        android:parentActivityName="com.jordanpeterson.textly.ui.LoginActivity"
        android:screenOrientation="portrait" >
    </activity>

- <activity android:name="com.jordanpeterson.textly.ui.EditFriendsActivity" android:label="@string/title_activity_edit_friends" android:parentActivityName="com.jordanpeterson.textly.ui.MainActivity" android:screenOrientation="portrait" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.jordanpeterson.textly.MainActivity" />

</activity>

    <activity
        android:name="com.jordanpeterson.textly.ui.RecipientsActivity"
        android:label="@string/title_activity_recipients"
        android:parentActivityName="com.jordanpeterson.textly.ui.MainActivity"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.jordanpeterson.textly.MainActivity" />
    </activity>

- <activity android:name="com.jordanpeterson.textly.ui.ViewImageActivity" android:label="@string/title_activity_view_image" android:parentActivityName="com.jordanpeterson.textly.ui.MainActivity" android:screenOrientation="portrait" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.jordanpeterson.textly.MainActivity" /> </activity> </application>

</manifest>

1 Answer

Hello,

In most of your Activity tags, you have

        android:parentActivityName="com.jordanpeterson.textly.ui.MainActivity"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.jordanpeterson.textly.MainActivity" />

where the android:parentActivityName and android.support.PARENT_ACTIVITY values do not match up. I'm going to guess that android:value="com.jordanpeterson.textly.MainActivity" will need to be changed to android:value="com.jordanpeterson.textly.ui.MainActivity" for all of the tags that use it. I'd also recommend placing the meta-data in on the Activity tags that do not have it. So in the end the Activity tags end up looking like

        android:parentActivityName="com.jordanpeterson.textly.ui.MainActivity"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.jordanpeterson.textly.ui.MainActivity" />

It works now! I figured it was just something little I was missing. Thank you for helping me! :)

You're welcome. Have fun with Android Development.