Krystine Monterde
Krystine Monterde

Reputation: 3

Android code having error at the back-end. Yet I can't figure where the code goes wrong

I'm at lost on what was wrong with my code. It won't show the page and I'm certain the error is somewhere in the Java code. Since I check the layout and its working perfectly not until I put the back-end. But I just can't figure where is that error is. So please somebody help me.

package calculator.apk;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class signMeup extends ActionBarActivity {

    Button sign;
    EditText name,birthD,birthM,birthY,pass;
    String fname,passWord,bdate,bmonth,byear,gender;
    CheckBox checkgen;
    RadioButton female, male;
    RadioGroup group;

    int inputField;


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

        name = (EditText) findViewById (R.id.editText1);
        birthD = (EditText) findViewById (R.id.editText2);
        birthM = (EditText) findViewById (R.id.editText3);
        birthY = (EditText) findViewById (R.id.editText4);
        pass = (EditText) findViewById (R.id.editText5);
        male =(RadioButton) findViewById (R.id.radioButton1);
        female =(RadioButton) findViewById (R.id.radioButton2);
        group = (RadioGroup)findViewById(R.id.radioGroup);

        sign.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                try{
                fname = name.getText().toString();
                checkInput (fname);
                bdate = birthD.getText().toString();
                checkInput(bdate);
                bmonth = birthM.getText().toString();
                checkInput(bmonth);
                byear = birthY.getText().toString();
                checkInput(byear);
                passWord = pass.getText().toString();
                checkInput(passWord);
                checkRadioButton();


                Intent intent = new Intent(getBaseContext(), profile.class);
                intent.putExtra("fName", fname);
                intent.putExtra("bDate", bdate);
                intent.putExtra("bMonth", bmonth);
                intent.putExtra("bYear", byear);
                intent.putExtra("pWord", passWord);
                intent.putExtra("genDer", gender);

                startActivity(intent);
                }
                 catch (Exception e) { 
                     // do nothing
                 }

            }
        });     
    }

    public void checkRadioButton()
    {

        int index = group.getCheckedRadioButtonId();
        if(index==-1){
            inputField++;
        }
        else{
            //Checking for Male
            if(male.isChecked()){
                gender="Male";
                Toast.makeText(getApplicationContext(), "You selected Male.", Toast.LENGTH_SHORT).show(); 
            }
            //Checking for Female
            else if(female.isChecked()){
                gender="Female";
                Toast.makeText(getApplicationContext(), "You selected Female.", Toast.LENGTH_SHORT).show(); 
            }
        }
    }

    public void checkInput(String input)
    {
        if(input.matches("")){
            inputField++;
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.calcu, 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);
    }
}

Upvotes: 0

Views: 41

Answers (1)

theJango
theJango

Reputation: 1108

In the following line you are getting NULL POINTER EXCEPTION

sign.setOnClickListener(new View.OnClickListener() {

because you never initialize your Button sign like the other attributes.

sign = (Button)findViewById(R.id.yourButtonId);

Upvotes: 1

Related Questions