0

I have received the following unexpected error while trying to run my activity:

Invalid type for value: class android.widget.TextView

Essentially I am trying to store data into Parse.com, where a user would select their calendar date and time through button clicks, and where the date and time selected would be recorded and shown into two TextViews that is displayed to them (Date and Time). Now I want to grab the TextViews information and record it into parse.

Below is the logcat message:

    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)

Below is the Activity code

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();
}
}


}

If you require any additional information, or clarification, let me know.

1 Answer 1

2
currentUser.put("ActivityDate", txtDate); 
currentUser.put("ActivityTime", txtTime);

Above two lines require ("key",value) pair.As you are passing only the TextView widget its causing exception.

Replace your line with these

currentUser.put("ActivityDate", txtDate.getText().toString()); 
currentUser.put("ActivityTime", txtTime.getText().toString());

EDIT For Validation of your textView do this in your onclick method:

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();


        }
    });
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your prompt answer. Would there be a way for me to set a condition where unless the textViews date and time have been set, the confirm button would not take the user to the next activity page, because initially when the activity loads what is displayed in the two textviews are hints like select your date, and select your time, which obviously I would not want to record blank information into parse
Thank you for your prompt response. I seem to be receiving the following error: Syntax error on token "else", delete this token, I tried moving the curly braces around, but I am assuming that it is a formatting issue. else{ Toast t = t.makeText(context,"Please fill all the details !",Toast.Length_LONG);
Toast t = Toast.makeText(ScheduleMatchOptionActivity.this ,"Please fill all the details !",Toast.LENGTH_LONG);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.