ERROR when compiling my code in Android Studio

1

When compiling my Android code, I'm getting the following error:

  

Error: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:   Error: Execution failed for task ': app: mergeDebugResources'.    Error: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:

This is mainActivity :

package com.example.eduarceleita.hojadevida;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
}

The R. comes out in red color as you can see in the image

main_activity.xml :

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    android:text="Eduar Alfonso Celeita"
    android:id="@+id/textView" />

<ImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    app:srcCompat="@drawable/foto"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="50dp"
    android:layout_gravity="center"
    android:id="@+id/imageView"
    android:contentDescription="" />

<Button
    android:text="Perfil profesional"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button" />

<Button
    android:text="Formacion academica"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button2" />

<Button
    android:text="Experiencia Laboral"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button3" />

<Button
    android:text="Referencias"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button4" />

<Button
    android:text="Idiomas"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button5" />

I would like to know what is happening and why this error is generated please help me!

    
asked by Eduar Celeita 27.12.2016 в 20:26
source

3 answers

1

When the class R is displayed in a red color it means that there is a problem in the resources.

To correct the problem with the class R.java , check the resources within the directory /res probably a layout or view has some kind of problem.

Remember that the layout that loads your Activity is called activity_main.xml

 setContentView(R.layout.activity_main);

When reviewing your layout the problem is easily detectable, you are using the app:srcCompat property in your ImageView, which is incorrect since you do not use the compatibility class AppCompatImageView , you must use the property:

 app:src="@drawable/foto"

You can see this in the explanation of this question, in which the user has a similar problem:

Show image in AndroidStudio simulator

  

I have seen what the problem is, in your layout you are using    app:srcCompat to load the image, if so you must use the class of   compatibility android.support.v7.widget.AppCompatImageView :

    <android.support.v7.widget.AppCompatImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/javi"
        android:id="@+id/imageView6">
</android.support.v7.widget.AppCompatImageView>
     

otherwise using the ImageView class, you should use only the   property android:src to assign the image:

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/javi"
        android:id="@+id/imageView6">
   </ImageView>
     
  • In both cases, it ensures that the specified image is actually inside the folder /drawable
  •   
    
answered by 31.12.2016 в 00:15
0

In your xml I was in ImageView with an image called a photo. I do not know if you're having that in your project. app: srcCompat="@ drawable / photo"

To compile on my machine, I take out the image.

Modify your xml a bit:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="Eduar Alfonso Celeita"
        android:id="@+id/textView" />

    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:layout_gravity="center"
        android:id="@+id/imageView"
        android:contentDescription="" />

    <Button
        android:text="Perfil profesional"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button" />

    <Button
        android:text="Formacion academica"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button2" />

    <Button
        android:text="Experiencia Laboral"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button3" />

    <Button
        android:text="Referencias"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button4" />

    <Button
        android:text="Idiomas"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button5" />
</LinearLayout>

    
answered by 28.12.2016 в 00:12
0

Sometimes for some reason that I still can not find Android Studio it does not matter the R class, for that reason it comes out in red color, to solve that error try looking at the imports in your MainActivity class, if you do not see the imported R-Class try add it manually like this:

import com.example.eduarceleita.hojadevida.R;

It has happened to me a couple of times.

Greetings.

    
answered by 30.12.2017 в 07:46