Home » Android » Android xml layout file is not being added to R.java

Android xml layout file is not being added to R.java

Posted by: admin May 14, 2020 Leave a comment

Questions:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<ImageView
    android:id="@+id/imageNew"
    android:layout_width="50dip"
    android:layout_height="50dip"
    android:src="@drawable/icon"
    android:scaleType="centerCrop"/>




</LinearLayout>

This is my new layout file and it is not being detected by eclipse, nor is it in the R file. I can’t create any new layout files or perhaps I’m doing it all wrong. All my older layouts are seen fine.

EDIT:

Also, a layout I had created previously I have edited with a new ID, however that new id is not detected either.

How to&Answers:

Clean your project or restart the eclipse, i guess it’s the problem with eclipse automatic building.

Answer:

Look to the imports, the R imported maybe is not correct.

Answer:

I have this import

import android.R;

I’ve deleted this and layout is working again

Answer:

If ANYTHING is wrong in your layouts, new updates aren’t added to the R file. Look at the errors panel, and possibly to a clean rebuild to see what errors are popping up.

Your layout xml is fine. The file itself may have an incompatible name.

Answer:

I had the same issue. I took Eclipse’s advice and removed

import android.R;

And replaced all references to R with the fully qualified name [project-specific package].R since the R file was actually being generated under some package, and the default contained nothing of interest.

You can check the package name by looking in the gen folder.

Answer:

My development environment: [ MacBook Pro, Eclipse: 4.4.0]

I’ve tried all of the above, but no sucess.

Its resolved in the following steps:

Step-1)Comment out import android.R;
Or,
Remove it complete.

Step-2) import packageName.R;

OR,

import com.arundhwaj.augmented_reality.R;

Hope it help someone.

Answer:

Probably problem in a name xml a file. The name shouldn’t contain upper case symbols.

Answer:

In my case the IDE (Eclipse) added the import android.R again and again. I had to update my Android SDK to make that go away.

Answer:

I had the same problem and I solve it renaming the xml file with lowercase symbols.

Answer:

I had this same problem and fixed it by adding

android:id="@+id/container"

underneath

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

Answer:

In my case I found out that when I’had just started the project I renamed the package but the refactory function didn’t canghe the name of the package of the generated code… so renaming that I corrected the missmatch.

Answer:

This can be a auto build issue with eclipse. So even if you remove android.R and do clean-build the issue may not go away. And prevent any R.java files to be created in the gen folder

  1. Remove import android.R (The R referred should be you package R not the android.R)
  2. Make sure the project is error free for a successful build. You can comment out error throwing references to R in project (if on worst case comment all R references).
  3. Clean the Project

  4. This should remove all the stale references and do a fresh compilation. Once the R.java is generated. Uncomment all R references . Now the layout and other references which were not getting recognized previously should resolve

Answer:

I changed
{ android:src=”@drawable/Myapp” } to
{ android:src=”@drawable/myapp” } in my layout.xml then I could select R.layout.mylayout in Mainactivity.java

Capital letters are not allowed.

Answer:

If you are facing same issue Just “Clean” the Project it should work.

Answer:

Instead of using android.R.layout. use
R.layout.new_layout_file

EXAMPLE, in arrayadapter **ArrayAdapter<E> item= new ArrayAdapter<>(this,R.layout.list_item,array); where E is the object** 

Answer:

One more reason that this can happen. If for example you add a new module and you give it an existing package name, you’ll get duplicate BuildConfig.java class files built. The mergeDexRelease and mergeDexDebug gradle task won’t like that and fail with an error “Program type already present” followed by the name of the duplicate class.

If you didn’t notice the error, you’ll see things like R.id.yourLayout or R.drawable.yourIcon being undefined in your app. Ironically string resources can still be found. The correction is to change the package name in one of the modules with the duplicate name.

If you want to find the locations of the duplicate classes in Android Studio, use “Navigate/Class…” and enter the name of the duplicate class. You might need to check the “include non-project items”