WTF?!?! How do I open res/layout/main.xml file?!?!


Last Updated:

  1. Christophe2010

    Christophe2010 Active Member This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    35
    Likes Received:
    4
    this stupid website(developer.adroid.com) is so vague! I'm in the resources section trying to do the Hello Views tutorial with the linear layout and it says:

    1) Start a new project named HelloLinearLayout
    2) Open the res/layout/main.xml file and insert the following: (xml code...)

    ok so...I opened up Eclipse. File > New > Project. I named my new project HelloLinearLayout. Ok. Then how the heck do i "open the res/layout/main.xml file"??!?! I click Open and there is no "res/layout/main.xml" file. Please help!
     

    Advertisement
  2. gorn

    gorn Well-Known Member

    Joined:
    Mar 22, 2010
    Messages:
    48
    Likes Received:
    11
    I actually find the developer.android.com resource very good.

    File > New > Android Project

    If you don't have an Android Project item you didn't install the eclipse add-ons correct. The developers.android.com website describes how to do this in the Setting up the SDK section.
     
  3. Christophe2010

    Christophe2010 Active Member This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    35
    Likes Received:
    4

    No no no no noooo, I have already the Android Project item! I just can't figure out how to open the "res/layout/main.xml file " and then be able to open the .java file of the source file which is HelloLinearLayout. Wtf I'm so confused. I know how to do Java, but this IDE is hella confusing.
     
  4. gorn

    gorn Well-Known Member

    Joined:
    Mar 22, 2010
    Messages:
    48
    Likes Received:
    11
    So you created an Android Project not a standard java project?
    Try Window > Open Perspective > Java if you're not already on that Perspective.
    Do you have the Package Explorer on the left hand side?
    Then in Package Explorer on the right hand side open your project and open res and open layout and open main.xml

    Maybe post a screenshot, sounds like you might have a weird layout or something.
     
    coder1 and Christophe2010 like this.
  5. Christophe2010

    Christophe2010 Active Member This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    35
    Likes Received:
    4
    Ok i have my java file...now how do I do this " in Package Explorer on the right hand side open your project and open res and open layout and open main.xml" I don't see an option to open res, layout, or main.xml...pleasee explain lol
     
  6. Christophe2010

    Christophe2010 Active Member This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    35
    Likes Received:
    4
    public​
    class HelloRelativeLayout
    {
    public static void main(String[] args)
    {
    HelloRelativeLayout hrl = new HelloRelativeLayout();

    hrl.onCreate();



    }
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }

    }​

    Step two tells me(btw, I'm on relative layout now..I got fed up with linear..lol) to; "Make sure you load this layout in the onCreate() method: " and this is the code it gave me:

    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }


    When i inserted this into my main, it gave me errors saying "The method onCreate() from the type HelloRelativeLayout refers to the missing type Bundle", and for the onCreate method, it says "Bundle cannot be resolved to a type" and inside the method it says "R cannot be resolved". What am I doing wrong? How can I fix this?

    Here's the link to the page: Relative Layout | Android Developers
     
  7. gorn

    gorn Well-Known Member

    Joined:
    Mar 22, 2010
    Messages:
    48
    Likes Received:
    11
    Are you sure you have an Android project and not a Java project?
     
    Christophe2010 likes this.
  8. markb

    markb Well-Known Member

    Joined:
    Sep 14, 2009
    Messages:
    148
    Likes Received:
    26
    Eclipse can have a bit of a learning curve, and be confusing at first.

    Can I check that your eclipse looks something like the screen-shot below.
    Do you have the Package Explorer panel shown at the left of the screen?
    Can you see and open up the res & layout folders and see main.xml?

    [​IMG]

    Mark
     
    coder1 and Christophe2010 like this.
  9. Christophe2010

    Christophe2010 Active Member This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    35
    Likes Received:
    4
    hmm, I don't have any of those folders(i only have the file name...which is HelloRelativeLayout.java, so maybe that's why?) in my package explorer....how did you get it to be able to have that res folder with drawable, layout, layout-land, raw, values, etc?
     
    coder1 likes this.
  10. markb

    markb Well-Known Member

    Joined:
    Sep 14, 2009
    Messages:
    148
    Likes Received:
    26
    The res folder along with all the others are created for you automatically when you start a new Android project. That's why gorn asked earlier if you were sure you had created an Android project rather than a standard Java project. It sounds like you don't have an Android project.

    Try following the instructions to create a new Android project to see what you get. You don't have to change anything you've already done, you can create another project just as a quick test.

    Use File -> New -> Android Project...

    Fill in the dialog box. The following screenshot is an example I used for someone else. Just for this test, try entering the same values to see what you get.

    [​IMG]

    Then have a look in the Package Explorer to see what files and folders were automatically created. Compare that with what you have for your existing project.

    Mark
     
    Christophe2010 likes this.
  11. Christophe2010

    Christophe2010 Active Member This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    35
    Likes Received:
    4
    everytime I try to start a new android project, it wont let me select a "SDK target"...and I've already add the SDK stuff to Eclipse but it just won't let me add or set my desired SDK target for the whole Eclipse program...:-/
     
  12. markb

    markb Well-Known Member

    Joined:
    Sep 14, 2009
    Messages:
    148
    Likes Received:
    26
    I think it would have been helpful if you'd said that at the start.

    Instead of this being a discussion about opening folders, it would have been about how to create a project and how to get the SDK set up correctly.

    People did ask earlier if you were sure you had an Android project. That would have been a good time to mention your sdk selection problem.

    I can't offer any more help at the moment as I'm away from my PC. (typing this on my nexus one, very slowly)
     
    Christophe2010 likes this.
  13. joeyv69ragtop

    joeyv69ragtop Member

    Joined:
    May 20, 2010
    Messages:
    16
    Likes Received:
    1
    It sounds like you have not installed any Android platforms.


    In Eclipse click Window -> Android SDK and AVD Manager
    on the left click Available Packages
    you should now see the URL to the android repository on google. click the + to expand it
    click the checkbox for the android platform you want to target with your app.
    click Install Selected on the bottom right
    click the radio button for Accept and click install

    Once the platform install is complete you should be able to select it as a build target when creating your android project.

    You'll also need to create an AVD on which to run/test your project unless you intend to do your testing directly on your phone.

    good luck
     
    Christophe2010 likes this.
  14. Christophe2010

    Christophe2010 Active Member This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    35
    Likes Received:
    4
    Hey all, thanks for the potential help and time! I fixed it! The reason why I couldn't do all this was because my path variable was missing...well, I had(for some reason..) ;c:\android\tools;...hahaha wtf. This is from that guy who posted about step by step on Eclipse and setting everything up...I guess I just wasn't paying attention. So, after adding C:\...android-sdk-windows\tools; to my path variable. *sigh* lol I feel so stupid. But, thanks to everyone again! I appreciate your assistance and time for something as stupid as my post :( sorry...ciao!
     
  15. coder1

    coder1 New Member

    Joined:
    Aug 18, 2010
    Messages:
    1
    Likes Received:
    0
    I have been searching for this, and the dang main.xml file!!! :confused:

    This entire thread has helped me find what I was looking for!!

    Eclipse is complex and it takes a lot of time to get used to...

    Thanks for all these posts, the one that helped me the most was the one that mark posted. I was checking the packages under projects in "Java Browsing" and could not find the res/layout/main.xml!!!

    So, I went to Window >> show view >> Project Explorer ... and then found my project and found the res/layout/ folder where I can edit the main.xml file.

    Thanks again to everyone who posted on this thread! :)
     
  16. preeti_soni

    preeti_soni New Member

    Joined:
    Jun 15, 2011
    Messages:
    1
    Likes Received:
    0
    It is simple
    First left click on left panel and u will see no. of folders
    there you will find res folder after that there are many folders like layout,values. You have to click on layout and ther you will find main.xml file where you can write your layout code.
    And I think so that it is not as much as stupid as you were saying , they give us complete url.
    SO if you have any problem now , then you can send me reply..........:)
     
  17. subu

    subu New Member

    Joined:
    Jul 30, 2011
    Messages:
    1
    Likes Received:
    0
    it can be found in the R.layout class. in the package explorer if you click on the main tab it opens up the R.java file. Instead right click on the main tab and say show in navigator. you will be able to find it under res->layout. Let me know if you still cant find it.
     

Share This Page

Loading...