Unable to set parent activity for new activities in Android Studio. Error: Hierarchical parent must already exist

I am starting to build my first app from developer.android.com. Recently switched to Android Studio and found that I can’t set the hierarchical parent for the new activity (DisplayMessageActivity). It states “Hierarchical Parent must already exist”. Can someone please guide me on this? In Eclipse, it works fine.

  • Do not request Window.FEATURE_ACTION_BAR issue
  • How to play radio live stream .asx video/x-ms-asf?
  • java.lang.IllegalArgumentException: Bad class: class java.util.GregorianCalendar
  • Android TLS connection and self signed certificate
  • Share a Facebook app ID across apps Android
  • NDK is not configured issue in android studio
  • Related posts:

    How to specify id when uses include in layout xml file
    Why use Android Picasso library to download images?
    Error with parsing Android sdk content and initializing java tooling in eclipse
    How to kill an Android activity when leaving it so that it cannot be accessed from the back button?
    Android programmatically disable autocomplete/autosuggest for EditText in emulator
    How do I configure the Android 4.0+ emulator to behave as a tablet?
  • How to get Bitmap from an Uri?
  • Warning using Glide in Recyclerview
  • Android Unable to instantiate activity: Didn't find class on path
  • Android Bluetooth logging filling up logcat
  • SQLite Query in non case sensitive alphabetical order
  • Android - accordion widget
  • 3 Solutions collect form web for “Unable to set parent activity for new activities in Android Studio. Error: Hierarchical parent must already exist”

    I was also doing the My First App tutorial on the Android Developer website using Android Studio and experienced this same problem. Thanks to charmarel for the tip that Android Studio will allow you to leave the problematic field blank. However, this will cause you do some of the legwork that the IDE would otherwise do for you in order to have the app properly running.

    The workaround is not all that bad:

    1. As mentioned, Android Studio (0.5.2) will allow you to leave the Hierarchical Parent field blank so just fill out the Activity Name, Layout Name, and Title as you normally would and ignore the Parent.
    2. Now about that legwork that is no longer being done for you… You will need to edit the AndroidManifest.xml file yourself to define the Parent Activity information for this new Activity as you have just left blank in the New activities dialog window.

    Edit the new Activity node to include this information, it should look like this:

        android:parentActivityName="com.example.myfirstapp.MainActivity" >
            android:value="com.example.myfirstapp.MainActivity" />

    That’s it, issue circumnavigated!

    I just ran into this same issue and I believe it’s an error in the latest update of Android Studio. I think you can get around this by manually creating a .java file for the activity.

    Edit: I experimented with this and found that you can make an activity using Android Studio and just leave the hierarchical parent blank, make sure the hierarchy is correct in the “package” section at the top of your new activity .java file, and it will be fine.

    I had the same issue in version 0.5.2 but it seems to now be working in 0.5.4, probably one of the many bug fixes.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.