Java 根据用户输入的EditText添加定期calenar事件

Java 根据用户输入的EditText添加定期calenar事件,java,android,date,calendar,Java,Android,Date,Calendar,我有我的应用程序,用户可以输入日期(yyyy/MM/dd),如果用户希望将事件添加到他们的日历中,则可以使用复选框。这是用于贷款支付(假设每月),因此我希望它选中要标记的框: if(addCalander.isChecked()) 宣言是: CheckBox addCalander = (CheckBox) findViewById(R.id.checkBox1); 一旦用户点击布局底部的“提交”框,我希望活动从不同的字段收集数据,验证复选框(如上)并假设选中,为贷款的基本期限向caland

我有我的应用程序,用户可以输入日期(yyyy/MM/dd),如果用户希望将事件添加到他们的日历中,则可以使用复选框。这是用于贷款支付(假设每月),因此我希望它选中要标记的框:

if(addCalander.isChecked())
宣言是:

CheckBox addCalander = (CheckBox) findViewById(R.id.checkBox1);
一旦用户点击布局底部的“提交”框,我希望活动从不同的字段收集数据,验证复选框(如上)并假设选中,为贷款的基本期限向calandar添加每月定期事件(我稍后会编程,但假设:

int debtTerm = 60; //60 months
下面是我的完整.java::

public void ButtonOnClick(View v)
{
    switch (v.getId()) {
    case R.id.buttonSubmit:

    TextView textDebtName = (TextView) findViewById(R.id.textDebtName);
    String debtName = textDebtName.getText().toString();
    TextView textDebtAmount = (TextView) findViewById(R.id.textDebtAmount);
    TextView textDebtRate = (TextView) findViewById(R.id.textDebtRate);
    TextView textDebtPayment = (TextView) findViewById(R.id.textDebtPayment);
    TextView textDebtDate = (TextView) findViewById(R.id.textDebtDate);

    EditText editDebtName = (EditText) findViewById(R.id.dispDebtName);
    EditText editDebtAmount = (EditText) findViewById(R.id.dispDebtAmount);
    EditText editDebtRate = (EditText) findViewById(R.id.dispDebtRate);
    EditText editDebtPayment = (EditText) findViewById(R.id.dispDebtPayment);
    EditText editDebtDate = (EditText) findViewById(R.id.dispDebtDate);



    CheckBox addCalander = (CheckBox) findViewById(R.id.checkBox1);
    String CalanderStr = addCalander.getText().toString();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");

    try {
        Date startDate = dateFormat.parse("string");
    } catch (ParseException e) {
        e.printStackTrace();
    }

    if(addCalander.isChecked())
    {
        Uri eventsUri;
        if (android.os.Build.VERSION.SDK_INT <= 7) {

            eventsUri = Uri.parse("content://calendar/events");
        } else {

            eventsUri = Uri.parse("content://com.android.calendar/events");
        }
        Calendar cal = Calendar.getInstance();  
        ContentValues event = new ContentValues();
        event.put("calendar_id", 1);
        event.put("title", debtName);
        event.put("description", "Loan Payment Due");
        event.put("eventLocation", "My Lender");
        event.put("dtstart",CalanderStr);
        event.put("rrule", "FREQ=MONTHLY;WKST=SU;BYDAY=SA");
        event.put("allDay", 1);   // 0 for false, 1 for true
        event.put("eventStatus", 1);
        event.put("hasAlarm", 1); // 0 for false, 1 for true
        event.put("duration","P90000S");
        Uri url = getContentResolver().insert(eventsUri, event);
    }

    break;
    }

}
错误似乎出现在脚本的以下部分:

Uri url = getContentResolver().insert(eventsUri, event);

你有没有申报你的按钮上的点击

<Button
        android:id="@+id/buttonSubmit"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:onClick="ButtonOnClick"
        android:text="Calculate (Minimum Payment)" />

您是否在按钮中声明了OnClick

<Button
        android:id="@+id/buttonSubmit"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:onClick="ButtonOnClick"
        android:text="Calculate (Minimum Payment)" />


您的submitButton是否有?您的submitButton是否有?这确实允许此时出现错误消息,因此这是一个步骤,请参见上文中的logCat。这确实允许此时出现错误消息,因此这是一个步骤,请参见上文中的logCat