Prakash Samy
Prakash Samy

Reputation: 91

can not resolve R in android studio?

I completed a registration form application. It runs perfectly, however; it is now showing a build error. How can I solve this?

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

            etusername=(EditText) findViewById(R.id.uname);
            etpassword=(EditText) findViewById(R.id.upassword);
            blogin=(Button) findViewById(R.id.blogin);
            registerlink=(Button) findViewById(R.id.register);
            blogin.setOnClickListener(this);
            registerlink.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            switch(v.getId()){
                case R.id.register:
                    startActivity(new Intent(this,RegisterActivity.class));
                    break;
                case R.id.blogin:

                    if(etusername.getText().toString().equals("admin") &&

                            etpassword.getText().toString().equals("admin")) {
                        startActivity(new Intent(this,HomeActivity.class));
                    }
                    else {
                        Toast.makeText(getApplicationContext(), "Invalid username/password", Toast.LENGTH_SHORT).show();
                    }

                        break;

            }
        }
    }

Upvotes: 2

Views: 1123

Answers (6)

jyo cool
jyo cool

Reputation: 11

I was also facing this issue when I changed my build variant in android studio. There are two png icon files missing in current build variant which are there in previuos build, added these two files to the current build and Rebuild project solved my problem. Hope this helps

Upvotes: 0

Sunil Chaudhary
Sunil Chaudhary

Reputation: 1247

1.check your XML files all Drawable images are there with the same name

2.check all imports in every activity and re-imports them

3.clear and rebuild

it may work if all are right

Upvotes: 0

hopeman
hopeman

Reputation: 2828

In Android Studio go to Build -> Clean Project Build -> Rebuild Project, if that doesn't work check your xml files for errors, sometimes they don't show up, but can cause this type of error.

Upvotes: 1

KDeogharkar
KDeogharkar

Reputation: 10959

there should be issue in your xml file . check your xml file in layout ,drawable folder and then clean your project.

Upvotes: 1

Martin Carpella
Martin Carpella

Reputation: 12583

Either your compiled for some other reasons so that R never got generated by Android Studio or you might be missing an import statement for it if you are in a different package.

Try a clean rebuild of the project and check if you need to import R.

Upvotes: 0

mattfred
mattfred

Reputation: 2749

Typically you can fix this error by cleaning your project, and then rebuilding it.

Build -> Clean Project Build -> Rebuild Project

Upvotes: 2

Related Questions