比较日期时显示警报时出错

时间:2014-08-12 08:01:39

标签: android

我是Android的新手尝试添加用户联系的一些出生日期,并将数据库中存储的这些日期与系统的当前日期进行比较,下面是我的代码,它成功存储数据但是,然后在警告对话框中显示一些问题部分,警报不起作用,任何人都可以帮助

public class start extends Activity {

// Button b1, b2, b3, b4;
ImageView i1, i2;
entry entry;
String date[];
String name[];
String cono[];

String month[] = { "Jan", "Feb", "March", "Apr", "May", "Jun", "Jul",
        "Aug", "Sep", "Oct", "Nov", "Dec" };
int num[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

@SuppressLint("SimpleDateFormat")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.example.forget.R.layout.start);

    final Context context = this;
    i1 = (ImageView) findViewById(com.example.forget.R.id.imageView1);
    i2 = (ImageView) findViewById(com.example.forget.R.id.imageView2);

    final Intent intent = new Intent(this, MainActivity.class);
    final Intent intent1 = new Intent(this, show.class);

    String da = getDate();
    System.out.println(da);

    // get data by Dob
    entry = new entry(context);

    List<Event> event = entry.getdatabByDate(da);

    Iterator li = event.iterator();

    String dateev = "";
    String nameev = "";
    String conodob = "";
    while (li.hasNext()) {
        Event event2 = (Event) li.next();
        dateev = event2.getDob() + "/" + dateev;
        conodob = event2.getContact() + "/" + conodob;
        nameev = event2.getName() + "/" + nameev;
    }

    date = dateev.split("/");
    name = nameev.split("/");
    cono = conodob.split("/");

    for (int i = 0; i < date.length; i++) {
        if (date[i].equals(da)) {
            final String n = name[i];
            final String con = cono[i];
            AlertDialog.Builder ab = new AlertDialog.Builder(context);
            ab.setTitle("Your Title");
            ab.setMessage("Today " + n + " Birthday")
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface arg0,
                                        int arg1) {

                                    sendSms(con);

                                }
                            })

                    .setNegativeButton("CANCEL",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {

                                    Toast.makeText(getApplicationContext(),
                                            "NO", 4000).show();

                                }
                            });

            AlertDialog ab1 = ab.create();
            ab1.show();

        }
    }

    i1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            startActivity(intent);

        }
    });

    i2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            startActivity(intent1);

        }
    });
}

public void sendSms(String conoOfDob) {
    Toast.makeText(getApplicationContext(), conoOfDob, 4000).show();

    /*
     * PendingIntent
     * pendingIntent=PendingIntent.getActivities(getApplicationContext(), 0,
     * null, 0); SmsManager sms=SmsManager.getDefault();
     * sms.sendTextMessage(conoOfDob, null, "Happy Bday", pendingIntent,
     * null);
     */

}

public void SendSms(String conoOfDob) {
    Toast.makeText(getApplicationContext(), conoOfDob, 4000).show();

    /*
     * PendingIntent
     * pendingIntent=PendingIntent.getActivities(getApplicationContext(), 0,
     * null, 0); SmsManager sms=SmsManager.getDefault();
     * sms.sendTextMessage(conoOfDob, null, "Happy Bday", pendingIntent,
     * null);
     */

}

@SuppressLint("SimpleDateFormat")
public String getDate() {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("M-dd");
    String strDate = sdf.format(cal.getTime());

    Toast.makeText(getApplicationContext(), strDate, 2000).show();

    return strDate;

}

}

1 个答案:

答案 0 :(得分:0)

以下是create simple alertdiaglog框的link。检查一下并发布错误日志,以便我们知道您的代码出了什么问题。