得到一个空指针异常

时间:2016-03-23 08:24:10

标签: android

我的代码是这样我无法找到错误空指针异常onclick我正在使用内部数据库和项目片段

public class FragmentAvion extends Fragment实现了View.OnClickListener {

private OnFragmentInteractionListener mListener;

private DataBaseManagerVuelo managerVuelo;
private Button button;
private EditText vaerolinea;
private EditText vdestino;
private EditText vconfirmacion;
private EditText vvuelo;
private Spinner spinner3;
private Button botonguardar;

public FragmentAvion() {
    // Required empty public constructor
}

public void setDate(View view) {
    DateDialog datedialog = new DateDialog();
    datedialog.show(getFragmentManager(), "DateDialog");
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_fragment_avion, container, false);

    Spinner spinner3 = (Spinner) view.findViewById(R.id.spinner3);
    final String vaerolinea = spinner3.getSelectedItem().toString();
    final EditText vvuelo = (EditText) view.findViewById(R.id.vvuelo);
    final EditText vconfirmacion = (EditText) view.findViewById(R.id.vconfirmacion);
    final EditText vdestino = (EditText) view.findViewById(R.id.vdestino);
    DatePicker dpResult = (DatePicker) view.findViewById(R.id.dpResult);
    TimePicker tpResult = (TimePicker) view.findViewById(R.id.tpResult);
    Button bottonguardar = (Button) view.findViewById(R.id.bottonguardar);
    bottonguardar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            managerVuelo.insertar_6parametros(null, vaerolinea, vvuelo.getText().toString(), vdestino.getText().toString(), null, null);
        }
    });



    return (view);
}

@Override
public void onClick(View v) {
    managerVuelo.insertar_6parametros(null, vaerolinea.getText().toString(), vvuelo.getText().toString(), vdestino.getText().toString(), null, null);
    }





    // Inflate the layout for this fragment



// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
    FragmentComidas.OnFragmentInteractionListener mListener = null;
    if (mListener != null) {
        mListener.onFragmentInteraction(uri);
    }
}



@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof FragmentViajeNuevo.OnFragmentInteractionListener) {
        mListener = (FragmentAvion.OnFragmentInteractionListener) context;
    } else {
        throw new RuntimeException(context.toString()
                + " must implement OnFragmentInteractionListener");
    }
}


@Override
public void onDetach() {
    super.onDetach();
    mListener = null;
}




public interface OnFragmentInteractionListener {
    void onFragmentInteraction(Uri uri);
}

}

1 个答案:

答案 0 :(得分:0)

看起来DataBaseManagerVuelo managerVuelo未初始化,您应该在onAttach或之后的某个时刻初始化它。