When adding an (empty activity), the class generates with the appropriate layout file but in the setContentview(R.layout.activity_home)
it gives an error.
This is my (empty) class:
package com.test.learnlogin;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class HomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
}
And this is the layout file to refer to:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
I am assuming that the name activity_home
inside setContentView
is of red color.
if yes and you are sure that activity_home
file exists in Res
> Layout
then please Restart
Your Android Studio
, that All
You'll have to import R to remove that error.
import com.test.R // assuming your_package_name=com.test
at the top.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.