0
package com.example.dictionary.mRecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class ViewHolder extends RecyclerView.ViewHolder {

    public TextView list_title;
    public TextView list_desc;

    public ViewHolder(View itemView) {
        super(itemView);

        list_title = (TextView) itemView.findViewById(R.id.list_title);
        list_desc = (TextView) itemView.findViewById(R.id.list_desc);
    }

}

in itemView.findViewById(R.id.list_title) and itemView.findViewById(R.id.list_desc) I get an error in R error message : package R does not exist

This is definitely code that should work. But this code is not running in my android studio. How can I get this code to work?

list_item.xml

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

    <TextView
        android:id="@+id/list_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="리스트 화면"
        android:textColor="#fff"
        android:background="#36384F"
        android:textSize="20sp"
        android:paddingLeft="20dp"
        android:paddingTop="20dp"
        android:paddingBottom="10dp"/>

    <TextView
        android:id="@+id/list_desc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="리스트 내용"
        android:textColor="#fff"
        android:background="#36384F"
        android:textSize="15sp"
        android:maxLines="2"
        android:ellipsize="end"
        android:paddingLeft="20dp"
        android:paddingBottom="20dp"/>

</LinearLayout>
  • 1
    Does this answer your question? [package R does not exist](https://stackoverflow.com/questions/12986301/package-r-does-not-exist) – Mohamed Rimshad Sep 06 '22 at 14:30

1 Answers1

1

possible solutions are:

  1. go to imports section in the code and add manually import
import com.example.dictionary.mRecyclerView.R;

  1. if you refactored the package name then you should change the package name in android manifest and app gradle file.
 applicationId "com.example.dictionary.mRecyclerView"

and in manifest file

 package="com.example.dictionary.mRecyclerView"
  1. if the above two steps not working, then you can try some technic which you can use to remove this error:-

    ☞ Clean your project, Build->clean Project

    ☞ Rebuild project, Build -> Rebuild Project

    ☞ Open manifest and check is there any resource missing

    ☞ Check-in layout to particular id if missing add it

    ☞ If the above steps did not work then restart android studio with invalidating the cache

ankor ank
  • 302
  • 5