• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

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

ceoceo39

Lurker
Hi, I'm beginner with Android.

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

fault1.jpg



Have anybody help me please???
 
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.
 
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.
 
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.
 
Even i got the same error.
R can not be resolved.
kindly post a reply for this
I got the same error. I added & removed the
Code:
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:
[COLOR=DimGray]clean:[/COLOR]
Deleting directory /home/chris/Projects/Java/FirstAndroid/bin
Deleting directory /home/chris/Projects/Java/FirstAndroid/gen
[COLOR=DarkRed]Creating output directories if needed...[/COLOR]
Created dir: /home/chris/Projects/Java/FirstAndroid/bin
Created dir: /home/chris/Projects/Java/FirstAndroid/gen
Created dir: /home/chris/Projects/Java/FirstAndroid/bin/classes
[COLOR=DarkRed]Compiling aidl files into Java classes...
Compiling RenderScript files into Java classes and RenderScript bytecode...
Generating R.java / Manifest.java from the resources...[/COLOR]
[COLOR=DimGray]compile:[/COLOR]
[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]
Compiling 2 source files to /home/chris/Projects/Java/FirstAndroid/bin/classes
[COLOR=DarkRed]Converting compiled files and external libraries into /home/chris/Projects/Java/FirstAndroid/bin/classes.dex...
Packaging resources[/COLOR]
Creating full resource package...
Creating FirstAndroid-debug-unaligned.apk and signing it with a debug key...
debug:
[COLOR=DarkRed]Running zip align on final apk...
Debug Package: /home/chris/Projects/Java/FirstAndroid/bin/FirstAndroid-debug.apk[/COLOR]
[COLOR=Green]BUILD SUCCESSFUL (total time: 3 seconds)[/COLOR]
Note: this is the basic, un-modified sample app that comes up in NetBeans for an Android App.
 
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.
 
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:orientation="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
 
>>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:
 
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
 
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.

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.
 
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.
 
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.
 
Hi, I'm beginner with Android.

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

fault1.jpg



Have anybody help me please???
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.
 

Attachments

  • Problem solving 1.jpg
    Problem solving 1.jpg
    178 KB · Views: 798
  • Problem solving 2.jpg
    Problem solving 2.jpg
    162.6 KB · Views: 641
  • Problem solving 3.jpg
    Problem solving 3.jpg
    57.8 KB · Views: 506
  • Problem solving and running.jpg
    Problem solving and running.jpg
    303 KB · Views: 627
Back
Top Bottom