-2

i am getting an error when i try to move to this activity in my app the app crashes giving the following error. is this the problem with this activity or i am not making the subclass properly.

Process: , PID: 14746 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.audiotest/com.example.audiotest.medical_record}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference

public class medical_record extends Npatient implements AdapterView.OnItemSelectedListener {

private DatabaseReference mDatabase;
Spinner HyperTension;
private String selectht;
ArrayAdapter adapter;

private Button bHistory;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle =getIntent().getExtras();

    final String firebasechild=bundle.getString("child");
    mDatabase = FirebaseDatabase.getInstance().getReference();

    HyperTension = (Spinner) findViewById(R.id.shypertension);
    bHistory = (Button) findViewById(R.id.bHistory);

    adapter =ArrayAdapter.createFromResource(this,R.array.History, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    HyperTension.setAdapter(adapter);
    HyperTension.setOnItemSelectedListener(medical_record.this);

    bHistory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            history hypertension = new history(selectht);
            mDatabase.child(firebasechild).push().setValue(hypertension);

            finish();
        }
    });



}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    TextView SpinnerDialogText = (TextView) view;
    selectht = SpinnerDialogText.getText().toString();
    Toast.makeText(this, "you selected " + SpinnerDialogText.getText(), Toast.LENGTH_SHORT  ).show();

}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}

}

1 Answers1

0

Are you passing any extras when you are opening this Activity? Like in this example below:

Intent intent = new Intent(getBaseContext(), YourActivity.class);
intent.putExtra("child", "firebase child string");
startActivity(intent);
Jan Slominski
  • 2,968
  • 4
  • 35
  • 61
  • i want to pass the string that have the link/address of the child to the next activity, so that i can access the same child from the next activity. – Abdul Samad Khan Mar 20 '17 at 15:11