ダイアログボックスを使用してデータベースに値を追加しようとしています。ただし、値は常にnullになるため、レイアウトから値を取得できないようです。これが私のコードです:
public class WlAddDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(com.mutoor.autoreply.R.layout.whitelistadd, null));
builder.setPositiveButton(com.mutoor.autoreply.R.string.add, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d("Dialog", "Starting dialog");
Context c = getActivity().getApplicationContext();
Log.d("Dialog", "Context Received");
WlHelper wl = new WlHelper(c);
Log.d("Dialog", "Created Whitelist Helper");
TextView eName = (TextView) getActivity().findViewById(R.id.entryName);
TextView eNumber = (TextView) getActivity().findViewById(R.id.entryNumber);
Log.d("Dialog", "Name = " + eName.getText().toString() + " , Number = " + eNumber.getText().toString());
wl.createEntry(eName.getText().toString(), eNumber.getText().toString());
dialog.dismiss();
}
});
builder.setNegativeButton(com.mutoor.autoreply.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
そして、これが私の出力です:
01-02 22:23:23.350: D/Dialog(26471): Starting dialog
01-02 22:23:23.350: D/Dialog(26471): Context Received
01-02 22:23:23.358: D/Dialog(26471): Created Whitelist Helper
01-02 22:23:23.358: D/AndroidRuntime(26471): Shutting down VM
01-02 22:23:23.358: E/AndroidRuntime(26471): FATAL EXCEPTION: main
01-02 22:12:57.373: E/AndroidRuntime(25973): java.lang.NullPointerException
01-02 22:23:23.358: E/AndroidRuntime(26471): at com.mutoor.autoreply.WlAddDialog$1.onClick(WlAddDialog.java:36)
どんな助けでも大歓迎です。