Why the up button throws an exception in Android learning “Create your first application”

I took all the steps in the last part ( Starting another action ), and it displays a message in the second action, but when I press the up button, it throws an exception below, I turned on the entire error section from the LogCat window.

I tried searching the Internet for “ bad parentActivityName ” or “ does not have a specified parental activity name, ” but I could not find any clear information or anything else related to the training.

E/Activity(17099): getParentActivityIntent: bad parentActivityName 'com.example.myfirstapp.MainActivity' in manifest
E/NavUtils(17099): getParentActivityIntent: bad parentActivityName 'com.example.myfirstapp.MainActivity' in manifest
D/AndroidRuntime(17099): Shutting down VM
E/AndroidRuntime(17099): FATAL EXCEPTION: main
E/AndroidRuntime(17099): java.lang.IllegalArgumentException: Activity DisplayMessageActivity 
    does not have a parent activity name specified. (Did you forget to add the 
    android.support.PARENT_ACTIVITY <meta-data>  element in your manifest?)

E/AndroidRuntime(17099):    at android.support.v4.app.NavUtils.navigateUpFromSameTask(NavUtils.java:177)
E/AndroidRuntime(17099):    at com.example.myfirstname.DisplayMessageActivity.onOptionsItemSelected(DisplayMessageActivity.java:55)
E/AndroidRuntime(17099):    at android.app.Activity.onMenuItemSelected(Activity.java:2548)
E/AndroidRuntime(17099):    at com.android.internal.widget.ActionBarView$3.onClick(ActionBarView.java:167)
E/AndroidRuntime(17099):    at android.view.View.performClick(View.java:4204)
E/AndroidRuntime(17099):    at android.view.View$PerformClick.run(View.java:17355)
E/AndroidRuntime(17099):    at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime(17099):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(17099):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(17099):    at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(17099):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17099):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(17099):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(17099):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(17099):    at dalvik.system.NativeStart.main(Native Method)
+5
source share
3 answers

, , .

: com.example.myfirstapp : com.example.myfirstname

- , , , , . , , .

' android.support.PARENT_ACTIVITY' , , .

+6

. -. ParentActivity IDE AndroidStudio. , AndroidStudio AndroidManifest.xml . , xml

<meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="____._____.MainActivity"/>
</activity>
+8

, :

1) , :

<manifest package="com.my.project" ...>

2) applicationId build.gradle (Module: app) :

defaultConfig {
    applicationId "com.my.project"
    ...
}

3) Check the spelling of android: the value of parent activity.

<meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="._____.MainActivity"/>
</activity>

If the first two steps are correct, you do not need to write the full namespace in step 3 !

+1
source

All Articles