我試圖從對話框中獲取一些值。我有一個名爲Splash的活動,它顯示一個帶有窗體的對話框。它顯示形式福利,但我給我一個錯誤,當我嘗試獲得該值(空指針)。從事件獲取變量/控件
我有如下因素代碼:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
//datos objeto
nombre = (TextView) findViewById(R.id.tv_nombre);
padre = (TextView) findViewById(R.id.tv_nom_padre);
madre = (TextView) findViewById(R.id.tv_nom_madre);
rgSexo = (RadioGroup) findViewById(R.id.rg_sexo);
fecha_nac = (DatePicker) findViewById(R.id.dp_fecha_nac);
rb_m = (RadioButton) findViewById(R.id.rb_masc);
rb_f = (RadioButton) findViewById(R.id.rb_fem);
perfil = new PerfilCRUD(this);
perfil.open();
//first time
if (perfil.primeraVez()){
//muestro el popup
Log.v(TAG, "prim vez");
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_perfil);
dialog.setTitle("Datos del usuario");
dialog.show();
Button botOk = (Button) dialog.findViewById(R.id.b_ok);
botOk.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Log.v(TAG, "boton ok");
Log.v(TAG, nombre.getText().toString());
}
});
它給我的錯誤,當我試圖讓nombre.getText()的toString()值。它發生在所有的變量/控制值。它迫使關閉應用程序。
謝謝!
是什麼logcat的說使用
name
? – 2013-04-08 16:55:20它說NullPointerException。 – alxsimo 2013-04-08 16:56:38
我必須使用視圖v對象,但我不知道如何.. – alxsimo 2013-04-08 17:01:28