0

I am new to android....I created a project in which I created a studreg.class and studreg.xml file.have also craeted a string.xml as I used want to create spinner..

Now setContentView is not recognizing studreg.xml and also I cannot see any R.java in gen folder.see following cod and help me.

studreg.xml**
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">IITKOL</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="qualification">Select Highest Qualification</string>
<string-array name="list_qualification">
    <item>item1</item>
    <item>item2</item>
    <item>item3</item>
    <item>item4</item>
    <item>item5</item>
    <item>item6</item>
    <item>item7</item>
    <item>item8</item>
   </string-array>
</resources>


studreg.java**
package iitkol.com;

import android.app.Activity;
import android.R;
import android.content.ContentValues;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;


public class studreg extends Activity{
protected static final int LENGTH_LONG = 0;
private TextView st_heading;
private EditText st_name,st_phno,st_email;
private Spinner st_course,st_qlf;
private Button st_submit,st_reset;
private DataHelper dataHelper;


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.studreg);
    st_heading=(TextView)findViewById(R.id.heading);
    st_name=(EditText)findViewById(R.id.edit_name);
    st_phno=(EditText)findViewById(R.id.edit_contact);
    st_email=(EditText)findViewById(R.id.edit_emailid);
    st_course=(Spinner)findViewById(R.id.course);
    st_qlf=(Spinner)findViewById(R.id.qlf);
    st_submit=(Button)findViewById(R.id.btn_submit);
    st_reset=(Button)findViewById(R.id.btn_reset);

    st_submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ContentValues contentValues = new ContentValues();
                    contentValues.put("studname",st_name.getText().toString().trim());
                    contentValues.put("studphno",st_phno.getText().toString().trim());
                contentValues.put("studemail",st_email.getText().toString().trim());
                contentValues.put("studqlf",st_qlf.getContext().toString().trim());
                contentValues.put("studcourse",st_course.getContext().toString().trim());
            dataHelper.insert("studform",contentValues);
            Toast.makeText(studreg.this,"Thanks for registering.We will contact you shortly",LENGTH_LONG).show();


        }

    });


}

strings.xml** 

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">IITKOL</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="qualification">Select Highest Qualification</string>
<string-array name="list_qualification">
    <item>item1</item>
    <item>item2</item>
    <item>item3</item>
    <item>item4</item>
    <item>item5</item>
    <item>item6</item>
    <item>item7</item>
    <item>item8</item>
   </string-array>
</resources>
Payal Garg
  • 31
  • 5

2 Answers2

0

Since you have no R.java file in your gen folder that means your xml file views will not be detected beacuse in r.java file we have our xml views (like buttons ,image views etc) id's The compiler generates id's for each view that is in your xml. As u said there is no R.java in ur project that simply means the setContentView will not detect ur xml file. So in order to remove this error u must firsr generate the R.java file.

To generate the file u must clean the project and build it again. The eclipse will generate the file again. But sometimes it does not generate so there is another way also if the above method will not work then try to change the workspace and import that project to new workspace then clean and build it again.

  • pls help me with this problem http://stackoverflow.com/questions/40017700/cursorboundexception-whille-displaying-listview-from-content-provider?noredirect=1#comment67354557_40017700 – Payal Garg Oct 14 '16 at 11:54
0

You pasted your strings.xml under studreg.xml in your post. Please double check.

Usually if there's an error in your xml, the compiler will fail to generate the R.java, and all your java code that uses R.xxx.xxx will get errors.

Xiaoyu Yu
  • 725
  • 3
  • 12