12

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.

dknchris
  • 487
  • 9
  • 17

3 Answers3

4

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.

charmarel
  • 69
  • 1
  • 7
  • 2
    Thanks. It works the way you said. However, for starters like me I believe it's wise to stay away from Android Studio until I capture the basics. – dknchris Mar 11 '14 at 02:42
  • 1
    @user3397618 That is the decision I made. I started with Eclipse. Recently, though, I switched to Android Studio and am loving it. – theblang Mar 12 '14 at 18:22
  • 1
    Was having the same problem :/ it worked correctly in the .4.8, but as you said...Android Studio is a pain in the ass as you start, but then...It's the most amazing thing :) – Rudy_TM Mar 19 '14 at 00:14
  • @charmarel: Leaving it blank allowed me to create the new Activity; however, what do you mean by "make sure the hierarchy is correct in the "package" section at the top of your new activity .java file"? All I have prior to the imports statements in the new Activity file is "package platypus.app;" What should it be instead or in addition to that? – B. Clay Shannon-B. Crow Raven Apr 07 '14 at 23:20
4

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:

<activity
    android:name="com.example.myfirstapp.DisplayMessageActivity"
    android:label="@string/title_activity_display_message"
    android:parentActivityName="com.example.myfirstapp.MainActivity" >
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.myfirstapp.MainActivity" />
</activity>

That's it, issue circumnavigated!

Derek W
  • 9,708
  • 5
  • 58
  • 67
2

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.

ThrowingSpoon
  • 861
  • 2
  • 12
  • 32
  • 1
    I had this problem within a couple of minutes of you answering here; 0.5.4 is the Canary channel version, correct? The asphyxiation-in-a coal-mine connotation of the ("Canary") name tends to trend trepidatious, though... – B. Clay Shannon-B. Crow Raven Apr 07 '14 at 23:09
  • 1
    That sounds like the same version as me. I should probably have mentioned I'm on OSX. Have you tried copying the package name from the class and then adding the class name to the end of it? I always do that because I can never remember what project I'm working on... – ThrowingSpoon Apr 07 '14 at 23:21