1. Download our Official Android App: Forums for Android!

Apps :( R.layout.main cannot be resolved :(

Discussion in 'Android Development' started by ceoceo39, Dec 22, 2008.

  1. ceoceo39

    ceoceo39 Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    2
    Joined:
    Dec 22, 2008

    Dec 22, 2008
    2
    1
    6
    Hi, I'm beginner with Android.

    The first simple code is a fault. I don't know how to fix it.

    [​IMG]


    Have anybody help me please???
     

    Advertisement

    geohussain1989 likes this.
  2. Silence

    Silence Lurker
    Rank:
    None
    Points:
    5
    Posts:
    6
    Joined:
    Dec 15, 2008

    Dec 15, 2008
    6
    0
    5
    I'm not sure if this will be of use anymore, but it looks like you are missing your R.java file in the package. It should be there under your sayhello.java file. Hope that helps.
     
  3. android_geek

    android_geek Lurker
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Nov 25, 2008

    Nov 25, 2008
    7
    0
    5
    under resources layout main.xml you are missing an entry

    Can you oost contents of the main.xml file?



     
  4. wrq19852004

    wrq19852004 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Mar 10, 2010

    Mar 10, 2010
    1
    0
    5
    To resolve this problem,you should comment the import android.R;
    such as :
    //import android.R
     
  5. Alonski

    Alonski Member
    Rank:
    None
    Points:
    35
    Posts:
    44
    Joined:
    Mar 4, 2010

    Mar 4, 2010
    44
    0
    35
    You don't have a gen folder which has the R.java file in it. I say you start over from scratch and build it EXACTLY how the tutorial states. I think that the R.java file is automatically created when you make a new android project so you are probably not doing that right.
     
  6. xoincare

    xoincare Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Sep 2, 2010

    Sep 2, 2010
    1
    0
    5
    It may sound paradoxical, I deleted the line on top of the [your main].java importing android.R.

    and it automatically resolved as normal.

    in my setting, I got my "automatically build" turned on.
     
  7. Ananya

    Ananya Lurker
    Rank:
    None
    Points:
    25
    Posts:
    2
    Joined:
    Sep 16, 2010

    Sep 16, 2010
    2
    0
    25
    Even i got the same error.
    R can not be resolved.
    kindly post a reply for this
     
  8. vladimirov

    vladimirov Newbie
    Rank:
    None
    Points:
    16
    Posts:
    17
    Joined:
    Apr 26, 2010

    Apr 26, 2010
    17
    2
    16
    Try to clean the project... eclipse->projects->clean
     
  9. fr34k

    fr34k Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Nov 18, 2010

    Nov 18, 2010
    1
    0
    5
    Remove import android.r;
     
  10. mohitjaitly

    mohitjaitly Member
    Rank:
    None
    Points:
    15
    Posts:
    34
    Joined:
    Oct 18, 2010

    Oct 18, 2010
    34
    0
    15
    India
    you should not import android.R.
    the gen folder on compilation automatically gets an 'R' class and this should be used in your app.
     
  11. wolfword

    wolfword Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jun 3, 2011

    Jun 3, 2011
    1
    0
    5
    Nanaimo, BC
    I got the same error. I added & removed the
    Code (Text):
    1. import android.R;
    to no effect. :( Then I compiled anyways ... and the error disappeared! :) But the red ! doesn't go away. Here's the build output:
    Code (Text):
    1.  
    2. [COLOR=DimGray]clean:[/COLOR]
    3. Deleting directory /home/chris/Projects/Java/FirstAndroid/bin
    4. Deleting directory /home/chris/Projects/Java/FirstAndroid/gen
    5. [COLOR=DarkRed]Creating output directories if needed...[/COLOR]
    6. Created dir: /home/chris/Projects/Java/FirstAndroid/bin
    7. Created dir: /home/chris/Projects/Java/FirstAndroid/gen
    8. Created dir: /home/chris/Projects/Java/FirstAndroid/bin/classes
    9. [COLOR=DarkRed]Compiling aidl files into Java classes...
    10. Compiling RenderScript files into Java classes and RenderScript bytecode...
    11. Generating R.java / Manifest.java from the resources...[/COLOR]
    12. [COLOR=DimGray]compile:[/COLOR]
    13. [COLOR=Blue][U]/home/chris/Projects/android-sdk-linux_x86/tools/ant/main_rules.xml:384[/U][/COLOR]: [COLOR=DarkRed]warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds[/COLOR]
    14. Compiling 2 source files to /home/chris/Projects/Java/FirstAndroid/bin/classes
    15. [COLOR=DarkRed]Converting compiled files and external libraries into /home/chris/Projects/Java/FirstAndroid/bin/classes.dex...
    16. Packaging resources[/COLOR]
    17. Creating full resource package...
    18. Creating FirstAndroid-debug-unaligned.apk and signing it with a debug key...
    19. debug:
    20. [COLOR=DarkRed]Running zip align on final apk...
    21. Debug Package: /home/chris/Projects/Java/FirstAndroid/bin/FirstAndroid-debug.apk[/COLOR]
    22. [COLOR=Green]BUILD SUCCESSFUL (total time: 3 seconds)[/COLOR]
    23.  
    Note: this is the basic, un-modified sample app that comes up in NetBeans for an Android App.
     
  12. cicoco

    cicoco Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jun 7, 2011

    Jun 7, 2011
    1
    0
    5
    have u ever config the PATH?
     
  13. anshulzunke

    anshulzunke Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Jul 22, 2011

    Jul 22, 2011
    3
    0
    5
    I also got stuck with this problem

    on my case problem was because of changing package of a java file and it didnt changed the autogenerated R.java package. When i changed the package back to original and removed import R.main. problem got resolved.
     
  14. vijaya

    vijaya Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Aug 17, 2011

    Aug 17, 2011
    1
    0
    5
    Even i got same Error but i rebuild the r.java also but no use getting same error
    this is my Sudoku.java
    if i remove android.R i get error at each button element in the below phrase.
    package com.wipro.sudokuActivity;

    import android.R;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;;
    public class Sudoku extends Activity implements OnClickListener
    {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    /** set up click listeners for all buttons */

    View continueButton = this.findViewById(R.id.button1);
    continueButton.setOnClickListener(this);
    View newButton = this.findViewById(R.id.button2);
    newButton.setOnClickListener(this);
    View instructionButton = this.findViewById(R.id.button3);
    instructionButton.setOnClickListener(this);
    View exitButton = this.findViewById(R.id.button1);
    exitButton.setOnClickListener(this);
    }
    public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button3:
    Intent i = new Intent(this, Instructions.class);
    startActivity(i);
    break;
    }

    }
    }





    this is Instructions.java file
    here also r.layout .main cant be resolved ..
    by aim is to create a button .when user clicks on dat button it should give description of that game....

    package com.wipro.sudokuActivity;
    //import android.R;
    import android.app.Activity;
    import android.os.Bundle;

    public class Instructions extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.instructions);
    }

    }


    this is my main.xml


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:eek:rientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background"
    android:gravity="center"
    >
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/Main_Title"
    android:textSize="15pt"
    android:layout_marginBottom="25dip"
    />
    <Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/first"
    />
    <Button
    android:id="@+id/button2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/second"
    />
    <Button
    android:id="@+id/button3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/third"
    />
    <Button

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/fourth"
    android:id="button1"/>
    </LinearLayout>


    this is my instuctions .xml

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:padding="10dip">
    <TextView android:id="@+id/instructions_content"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:text="@string/Instructions_text" />
    </ScrollView>



    please let me know as early as possible ...i appreciate your reply
     
  15. oosgearoo

    oosgearoo Member
    Rank:
    None
    Points:
    16
    Posts:
    35
    Joined:
    Aug 15, 2013

    >>R.layout.main cannot be resolved

    This problem still exist's even today I am trying to get this code to compile a straight HelloWorld application, based on a blank new project from Eclipse 'Kepler'(I think).

    I have read through your replies and it would seam as if i am missing a file, or an import option. I have added the import option but have had no luck with it the compiling stage still fail's on the R.layout.main

    If I am simply missing a file how do I generate the file' and whats in said file.

    A Blast from the past hopefully we can answer this for others this is my first post so HI and go easy.:mad:
     
  16. out of ideas

    out of ideas Android Enthusiast
    Rank:
    None
    Points:
    93
    Posts:
    641
    Joined:
    May 19, 2012

    May 19, 2012
    641
    145
    93
    these are pretty common and have a couple fixes

    1. Your layout is incorrect. Check all your XML files AGAIN AND AGAIN. you might think they are fine but they might not be so keep checking.
    2. make sure you're not importing android.R
    3. check your Jar dependencies. you may have an MD5 mismatch throwing it off.
    4. Try rebuilding your project
    5. Try cleaning your project
    6. Try closing out of eclipse and reopening it.

    One of these will prob fix it. If not, try them again
     
  17. mills2533

    mills2533 Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    150
    Joined:
    Dec 21, 2010

    Dec 21, 2010
    150
    22
    38
    Colorado (USA)
    Sometimes Eclipse doesn't immediately show you an error that may be in your XML files. Start by going through the xml files you most recently changed.

     
  18. oosgearoo

    oosgearoo Member
    Rank:
    None
    Points:
    16
    Posts:
    35
    Joined:
    Aug 15, 2013

    Many thanks for all the reply's.
    As for the cleaning of my computer well ile get that can of polish out on the HD right away(Joking).:p

    Thanks again.
     
  19. steve

    steve Developer
    Administrator
    Rank:
     #50
    Points:
    573
    Posts:
    1,071
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    1,071
    1,139
    573
    Male
    Android Developer
    York, PA
    For others having this issue as I see its a very common problem...

    99% of the time this is caused by your xml layout file(s) not being correctly formatted. Once you confirm this then delete the android.R import and then Eclipse (or IDEA, etc) will import the proper package resources. If not I would next try to clean cache.
     
  20. Zsolt Andri

    Zsolt Andri Lurker
    Rank:
    None
    Points:
    15
    Posts:
    1
    Joined:
    Apr 11, 2015

    I found solution :)))
    Please follow me:
    Project->Properties->Android->Project Build Target (choose Android Open Source Project 4.4 or higher version I choosed 5.1.1 )
    Next
    Project->Built all (Ctrl + B)

    Please test it.
     

    Attached Files:

Share This Page

Loading...