Error trying to access another screen using a button

0

My problem is this, I have my main screen that contains a button to access another screen, the code I'm using to make this connection is:

btRegister.setOnClickListener(new View.OnClickListener() {          
@Override
    public void onClick(View v) {
        setContentView(R.layout.activity_register);
    }
});

It happens that inside this new screen ( activity_register ) I have several fields (EditText) and two buttons, Register and Clear , the task button is that when it is pressed it collects the values of the fields (EditText) and inserts in String , for this I am using the following code:

Part 1:

EditText etRegisterName,etRegisterSecondName,etRegisterAge,etRegisterEmail,etRegisterPhone;

Part 2:

name = etRegisterName.getText().toString();
secondname = etRegisterSecondName.getText().toString();
age = etRegisterAge.getText().toString();
email = etRegisterEmail.getText().toString();
phone = etRegisterPhone.getText().toString();

In short, my MainActivy looks like this:

public class MainActivity extends ActionBarActivity {
    EditText etSearch;
    EditText etRegisterName,etRegisterSecondName,etRegisterAge,etRegisterEmail,etRegisterPhone;
    Button btSearch,btRegister,btRegisterFinish;

    String name, secondname, age, email, phone;

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

        etSearch = (EditText) findViewById(R.id.Search);
        btSearch = (Button) findViewById(R.id.Search_Button);
        btRegister = (Button) findViewById(R.id.Register_Button);
        btRegisterFinish = (Button) findViewById(R.id.btRegisterFinish);

        etRegisterName = (EditText) findViewById(R.id.etRegisterName);
        etRegisterSecondName = (EditText) findViewById(R.id.etRegisterSecondName);
        etRegisterAge = (EditText) findViewById(R.id.etRegisterAge);
        etRegisterEmail = (EditText) findViewById(R.id.etRegisterEmail);
        etRegisterPhone = (EditText) findViewById(R.id.etRegisterPhone);

        btSearch.setOnClickListener(new View.OnClickListener() {            
            @Override
            public void onClick(View v) {               
                String busca = etSearch.getText().toString();

                String tableTest = name+secondname+age+email+phone;

                String[][] table = {{"Rosana","De Oliveira","39","[email protected]","(00) 5555-5555"},
                                    {"Jackson","De Almeida","15","[email protected]","(00) 6666-66666"}};

                for(int i=0;i < table.length;i++){
                    for(int j=0;j < table[i].length;j++){

                        if(busca.contains(table[i][j]) == true){                            
                            AlertDialog.Builder searchOK = new AlertDialog.Builder(MainActivity.this);
                            searchOK.setTitle("Busca Concluida");
                            searchOK.setMessage("Nome: " + table[i][0] + "\n" 
                                                + "Sobrenome: " + table[i][1] + "\n" 
                                                + "Idade: "  + table[i][2] + "\n" 
                                                + "E-mail: " + table[i][3] + "\n" 
                                                + "Telefone: " + table[i][4]);

                            searchOK.setNeutralButton("Fechar", null);
                            searchOK.show();
                        }

                    }
                }
            }
        });
        btRegister.setOnClickListener(new View.OnClickListener() {          
            @Override
            public void onClick(View v) {
                setContentView(R.layout.activity_register);
            }
        });
        btRegisterFinish.setOnClickListener(new View.OnClickListener() {            
            @Override
            public void onClick(View v) {
                name = etRegisterName.getText().toString();
                secondname = etRegisterSecondName.getText().toString();
                age = etRegisterAge.getText().toString();
                email = etRegisterEmail.getText().toString();
                phone = etRegisterPhone.getText().toString();

                AlertDialog.Builder confirmRegister = new AlertDialog.Builder(MainActivity.this);
                confirmRegister.setTitle("Dados do Registro:");
                confirmRegister.setMessage("Nome: " + name + "\n"
                                            + "Sobrenome: " + secondname + "\n"
                                            + "Idade: " + age + "\n"
                                            + "E-mail: " + email + "\n"
                                            + "Telefone: " + phone);
                confirmRegister.setNeutralButton("Alterar", null);
                confirmRegister.setPositiveButton("Registrar", new DialogInterface.OnClickListener() {                  
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        setContentView(R.layout.activity_main);

                        AlertDialog.Builder alertSucess = new AlertDialog.Builder(MainActivity.this);
                        alertSucess.setTitle("Registrado!");
                        alertSucess.setMessage("Registro feito com Sucesso!");
                        alertSucess.setNeutralButton("OK", null);
                    }
                });
                confirmRegister.show();
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

My problem is that when I try to access this screen ( activity_register ) of the error saying that the application has stopped! I can not even access the other screen where the button to complete the Registry is, does anyone have any idea what it can be? if the question was confusing I'm sorry, leave it in the comments I'll try to explain better!

    
asked by anonymous 07.02.2015 / 22:20

0 answers