我在我的应用程序中尝试移动到此活动时收到错误,应用程序崩溃时出现以下错误。这是这个活动的问题,还是我没有正确地创建子类。
过程:,PID:14746 java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.audiotest / com.example.audiotest.medical_record}:java.lang.NullPointerException:尝试调用虚方法'java.lang.String android.os.Bundle。 null对象引用上的getString(java.lang.String)'
public class medical_record extends Npatient实现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) {
}
}
答案 0 :(得分:0)
打开此活动时,您是否传递任何额外内容?就像下面的例子一样:
Intent intent = new Intent(getBaseContext(), YourActivity.class);
intent.putExtra("child", "firebase child string");
startActivity(intent);