Home > database >  @layout/activity_main does not contain a declaration with id tvDescription
@layout/activity_main does not contain a declaration with id tvDescription

Time:10-03

I am getting the following error. during I am creating the

tvDescription = findViewById(R.id.tvDescription);

[Error]:--> @layout/activity_main does not contain a declaration with id tvDescription

public class MainActivity extends AppCompatActivity implements ListFrag.ItemSelected {

    TextView tvDescription;
    ArrayList<String> description;
    @Override`enter code here`
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layout.activity_main);

        tvDescription = findViewById(R.id.tvDescription);

        description = new ArrayList<>();
        description.add("Description for item 1");
        description.add("Description for item 2");
        description.add("Description for item 3");
        description.add("Description for item 4");
        description.add("Description for item 5");

    }

    @Override
    public void onItemSelected(int index) {
        tvDescription.setText(description.get(index));
    }

<TextView
    android:id="@ id/tvDescription"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:layout_marginRight="20dp"
    android:textSize="18sp"
    android:text="@string/description"
    android:textColor="@color/black"
    android:textStyle="bold" />

CodePudding user response:

Try changing setContentView(layout.activity_main);

To setContentView(R.layout.activity_main);

CodePudding user response:

Try to follow below steps:

  1. Clean and Rebuild Project.
  2. If issue is still there, Goto File ->Invaliadte Caches..

Update: I missed the bug I think @vijay-jv is right on pointing out exact mistake. use R.layout.activity_main instead of layout.activity_main

  • Related