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


Last Updated:

  1. ceoceo39

    ceoceo39 New Member This Topic's Starter

    Joined:
    Dec 22, 2008
    Messages:
    2
    Likes Received:
    1
    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 Member

    Joined:
    Dec 15, 2008
    Messages:
    6
    Likes Received:
    0
    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 Member

    Joined:
    Nov 25, 2008
    Messages:
    7
    Likes Received:
    0
    under resources layout main.xml you are missing an entry

    Can you oost contents of the main.xml file?



     
  4. wrq19852004

    wrq19852004 New Member

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

    Alonski Active Member

    Joined:
    Mar 4, 2010
    Messages:
    44
    Likes Received:
    0
    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 New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    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 New Member

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

    vladimirov Member

    Joined:
    Apr 26, 2010
    Messages:
    17
    Likes Received:
    2
    Try to clean the project... eclipse->projects->clean
     
  9. fr34k

    fr34k New Member

    Joined:
    Nov 18, 2010
    Messages:
    1
    Likes Received:
    0
    Remove import android.r;
     
  10. mohitjaitly

    mohitjaitly Active Member

    Joined:
    Oct 18, 2010
    Messages:
    34
    Likes Received:
    0
    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 New Member

    Joined:
    Jun 3, 2011
    Messages:
    1
    Likes Received:
    0
    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 New Member

    Joined:
    Jun 7, 2011
    Messages:
    1
    Likes Received:
    0
    have u ever config the PATH?
     
  13. anshulzunke

    anshulzunke New Member

    Joined:
    Jul 22, 2011
    Messages:
    3
    Likes Received:
    0
    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 New Member

    Joined:
    Aug 17, 2011
    Messages:
    1
    Likes Received:
    0
    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 Active Member

    Joined:
    Aug 15, 2013
    Messages:
    35
    Likes Received:
    1
    >>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 Well-Known Member

    Joined:
    May 19, 2012
    Messages:
    641
    Likes Received:
    145
    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

    Joined:
    Dec 21, 2010
    Messages:
    150
    Likes Received:
    22
    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 Active Member

    Joined:
    Aug 15, 2013
    Messages:
    35
    Likes Received:
    1
    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. stevealbright

    stevealbright Developer Administrator

    Joined:
    Apr 19, 2011
    Messages:
    598
    Likes Received:
    498
    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 New Member

    Joined:
    Apr 11, 2015
    Messages:
    1
    Likes Received:
    0
    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...