尝试运行我的活动时收到以下意外错误:
Invalid type for value: class android.widget.TextView
基本上我正在尝试将数据存储到Parse.com中,用户可以通过按钮点击选择日历日期和时间,并且选择的日期和时间将被记录并显示在显示给他们的两个TextView中(日期和时间)。现在我想获取TextViews信息并将其记录到解析中。
以下是logcat消息:
09-16 16:58:25.510: E/AndroidRuntime(1542): FATAL EXCEPTION: main
09-16 16:58:25.510: E/AndroidRuntime(1542): Process: com.dooba.beta, PID: 1542
09-16 16:58:25.510: E/AndroidRuntime(1542): java.lang.IllegalArgumentException: invalid type for value: class android.widget.TextView
09-16 16:58:25.510: E/AndroidRuntime(1542): at com.parse.ParseObject.put(ParseObject.java:2696)
09-16 16:58:25.510: E/AndroidRuntime(1542): at com.parse.ParseUser.put(ParseUser.java:404)
09-16 16:58:25.510: E/AndroidRuntime(1542): at com.dooba.beta.ScheduleMatchOptionActivity$1.onClick(ScheduleMatchOptionActivity.java:55)
09-16 16:58:25.510: E/AndroidRuntime(1542): at android.view.View.performClick(View.java:4438)
09-16 16:58:25.510: E/AndroidRuntime(1542): at android.view.View$PerformClick.run(View.java:18422)
09-16 16:58:25.510: E/AndroidRuntime(1542): at android.os.Handler.handleCallback(Handler.java:733)
09-16 16:58:25.510: E/AndroidRuntime(1542): at android.os.Handler.dispatchMessage(Handler.java:95)
09-16 16:58:25.510: E/AndroidRuntime(1542): at android.os.Looper.loop(Looper.java:136)
09-16 16:58:25.510: E/AndroidRuntime(1542): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-16 16:58:25.510: E/AndroidRuntime(1542): at java.lang.reflect.Method.invokeNative(Native Method)
09-16 16:58:25.510: E/AndroidRuntime(1542): at java.lang.reflect.Method.invoke(Method.java:515)
09-16 16:58:25.510: E/AndroidRuntime(1542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-16 16:58:25.510: E/AndroidRuntime(1542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-16 16:58:25.510: E/AndroidRuntime(1542): at dalvik.system.NativeStart.main(Native Method)
以下是活动代码
public class ScheduleMatchOptionActivity extends Activity implements
OnClickListener {
protected TextView mCalendarDate;
protected TextView mCalendarTime;
Button btnCalendar, btnTimePicker;
TextView txtDate, txtTime;
private int mYear, mMonth, mDay, mHour, mMinute;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.match_schedule);
txtDate = (TextView) findViewById(R.id.txtDate);
txtTime = (TextView) findViewById(R.id.txtTime);
Button mConfirm2 = (Button)findViewById(R.id.btnConfirmSchedule);
mConfirm2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseUser currentUser = ParseUser.getCurrentUser();
// Create the class and the columns
currentUser.saveInBackground();
currentUser.put("ActivityDate", txtDate);
currentUser.put("ActivityTime", txtTime);
currentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
// Success!
}
else {
}
}
});
}
});
btnCalendar = (Button) findViewById(R.id.btnCalendar);
btnTimePicker = (Button) findViewById(R.id.btnTimePicker);
txtDate = (TextView) findViewById(R.id.txtDate);
txtTime = (TextView) findViewById(R.id.txtTime);
btnCalendar.setOnClickListener(this);
btnTimePicker.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == btnCalendar) {
// Process to get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
// Launch Date Picker Dialog
DatePickerDialog dpd = new DatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
// Display Selected date in textbox
txtDate.setText(dayOfMonth + "-"
+ (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
dpd.show();
}
if (v == btnTimePicker) {
// Process to get Current Time
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
// Launch Time Picker Dialog
TimePickerDialog tpd = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
// Display Selected time in textbox
txtTime.setText(hourOfDay + ":" + minute);
}
}, mHour, mMinute, false);
tpd.show();
}
}
}
如果您需要任何其他信息或说明,请与我们联系。
答案 0 :(得分:2)
currentUser.put("ActivityDate", txtDate);
currentUser.put("ActivityTime", txtTime);
以上两行需要(“key”,value)对。因为你只传递TextView小部件而导致异常。
用这些
替换你的行currentUser.put("ActivityDate", txtDate.getText().toString());
currentUser.put("ActivityTime", txtTime.getText().toString());
修改强> 要验证textView,请在onclick方法中执行此操作:
mConfirm2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(txtDate.getText().toString().length()>0 && txtTime.getText().toString().length() >0 ){
ParseUser currentUser = ParseUser.getCurrentUser();
// Create the class and the columns
currentUser.saveInBackground();
currentUser.put("ActivityDate", txtDate);
currentUser.put("ActivityTime", txtTime);
currentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
// Success!
}
else {
}
}
});
}else{
Toast t = t.makeText(context,"Please fill all the details !",Toast.Length_LONG);
t.setGravity(Gravity.center,0,0);
t.show();
}
});