0

Tried everything like cleaning the project,installing SDK build tools,checking for errors in XML layout files. Still no way I can get rid of this "unexpected R error".

Below is the code for First.java

package com.example.wctm;



    import android.os.Bundle;
    import android.app.Activity;
    import android.content.DialogInterface;
    import android.content.DialogInterface.OnClickListener;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;

    public class First extends Activity implements OnClickListener {

        EditText name;
        EditText pass;
        Button   submit;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first);        
            name=(EditText)findViewById(R.id.editText1);
            pass=(EditText)findViewById(R.id.editText2);
            submit=(Button)findViewById(R.id.button1);
            submit.setOnClickListener((android.view.View.OnClickListener) this);
        }



    public void onClick(View v)
    {
        String na=name.getText().toString();
        String pa=pass.getText().toString();

        switch (v.getId()) {
        case R.id.button1:
            if(na.equals("wctm") && (pa.equals("wctm")))
            {
                Intent i=new Intent(this,Second.class);
                startActivity(i);
            }


            break;

        default:
            break;
        }

    }

        enter code here

    @Override
    public void onClick(DialogInterface arg0, int arg1) {

    }

}
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • It means that there's a problem in your XML views so the auto generated classes at compile time (which includes the definition of `R`) weren't generated **or** that you forgot to import it. – Luiggi Mendoza Mar 10 '14 at 15:35
  • possible duplicate of [R cannot be resolved to a variable](http://stackoverflow.com/questions/5592806/r-cannot-be-resolved-to-a-variable) – Will Sherwood Mar 10 '14 at 15:37
  • `checking for errors in XML layout files`. ONLY in **layout** files? what about strings, colors, dimens, ...? Also check for **upper case** letters in your file names. – Phantômaxx Mar 10 '14 at 15:37
  • http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error seems to have answered this. I had it myself once – onesixtyfourth Mar 10 '14 at 15:38
  • You most likely have an issue in one of your XML files (this includes strings, colors, dimens, ect). Some other things to try would be to delete your R.java file, and rebuild your project. This will regenerate a new R.java file. Also, attempt to restart your IDE as well. For more information, this site is great for your issue. http://ljtatum.blog.com/r/ – portfoliobuilder Mar 10 '14 at 15:38
  • 2
    You have problem with your xml files (note that you have to check all xml files not only the views). R is autogenerated and when you clean your project you delete it. Regarding to errors, R can't be generated and it missing. – Bosko Mijin Mar 10 '14 at 15:39
  • Checked all the XML Files still havent found any errors. – user3402356 Mar 10 '14 at 15:41
  • @portfoliobuilder-R.java file has not been generated yet.What could be the otherwise cause for this type of error? – user3402356 Mar 10 '14 at 15:44
  • If you do not have a R.java file, this would definately cause an issue. Look under your gen folder. You should see two files, BuildConfig.java and R.java. If R.java is not there delete your gen folder. Then clean your project (this should regenerate those files). And then for good measure, restart your IDE. – portfoliobuilder Mar 10 '14 at 15:50

0 Answers0