skedgo / DateTimeRangePicker

A date time range picker for android written in Kotlin
MIT License
505 stars 76 forks source link

time zone not come in kotlin to java #7

Closed rajam1215 closed 7 years ago

rajam1215 commented 7 years ago

Attempt to cast generated internal exception: java.lang.ClassCastException: java.util.SimpleTimeZone cannot be cast to java.lang.String

this error is coming

because behalf of code timezone come in string. but android studio show timezone not convert in string.

the timezone not come because when i give timezone in intent in java class. that will not taken by kotlin class. behalf your code , u send time zone. in DateTimeRangePicker. but in java class intent working type is different. i think u know.

how can i solve this issue. please give me a solution

Thanks

thuytrinh commented 7 years ago

Did you use newIntent() to launch DateTimeRangePickerActivity? How did you pass the instance of SimpleTimeZone into newIntent()? A code snippet would be very helpful to tackle the issue.

rajam1215 commented 7 years ago

Ok, The code is

            Intent intent = new Intent(MainActivity.this, DateTimeRangePickerActivity.class);
            intent.putExtra("",TimeZone.getDefault());
            startActivityForResult(intent, RQC_PICK_DATE_TIME_RANGE);

this is my java code. and i dont know witch way i send(java code) intent data in kotlin class

behalf your code u send data in intent with the syntax of kotlin.

please give me a solution

thuytrinh commented 7 years ago

That's an invalid usage. Pls make sure you always use newIntent() to launch DateTimeRangePickerActivity like described in https://github.com/skedgo/DateTimeRangePicker#usage. If you call it from Java code, make sure you invoke the Companion (e.g. DateTimeRangePickerActivity.Companion.newIntent(...)).

rajam1215 commented 7 years ago

hi

OK but i ask u how to call intent java to kotlin. i use this intent. because this intent method is use in java code. and u say (e.g. DateTimeRangePickerActivity.Companion.newIntent(...)). use intent with comapnion .

can u give me some code snippet of java code . that is help for me i think

thanks

rajam1215 commented 7 years ago

this error come , time zone null i use github code according u with companion. but time zone always null.

Attempt to cast generated internal exception: java.lang.ClassCastException: libcore.util.ZoneInfo cannot be cast to java.lang.String

rajam1215 commented 7 years ago
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RQC_PICK_DATE_TIME_RANGE && resultCode == Activity.RESULT_OK) {
        if (data != null) {
            long start = data.getLongExtra("startTimeInMillis", 0);
            long end = data.getLongExtra("endTimeInMillis", 0);
            String timezone = data.getStringExtra("timeZone");
            Log.e("Time", "Start : " + start + " end : " + end + " time : " + timezone);
        } else {
            Log.e("Time", "not come");
        }
    }
}

and this type i get data from main Activity in java class

thx

thuytrinh commented 7 years ago

The library uses Joda-Time to manipulate some date time logic under the hood. So you might need this https://github.com/dlew/joda-time-android#usage.

rajam1215 commented 7 years ago

Ok

currently i use intent like this

            Intent intent = DateTimeRangePickerActivity.Companion.newIntent(MainActivity.this, TimeZone.getDefault(), null, null);
            startActivityForResult(intent, RQC_PICK_DATE_TIME_RANGE);

OnActivityResult like this

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RQC_PICK_DATE_TIME_RANGE && resultCode == Activity.RESULT_OK) {
        if (data != null) {
            long start = data.getLongExtra("startTimeInMillis", 0);
            long end = data.getLongExtra("endTimeInMillis", 0);
            String timezone = data.getStringExtra("timeZone");
            Log.e("Time", "Start : " + start + " end : " + end + " time : " + timezone);
        } else {
            Log.e("Time", "not come");
        }
    }
}

and In Application class. i use

public class AppController extends Application {

@Override
public void onCreate() {
    super.onCreate();
    JodaTimeAndroid.init(this);
}

}

but steal this error come

Attempt to cast generated internal exception: java.lang.ClassCastException: libcore.util.ZoneInfo cannot be cast to java.lang.String at android.os.BaseBundle.getString(BaseBundle.java:923)

TimeZone steal null in OnActivityResult

Thanks

thuytrinh commented 7 years ago

Ok, I can recognize the problem now. DateTimeRangePickerViewModel put timeZone into Intent as Serializable instead String. Will deliver the fix.

thuytrinh commented 7 years ago

Fixed by https://github.com/skedgo/DateTimeRangePicker/commit/7194744eb61476cee2aa6e9d568350df14545ea9.

rajam1215 commented 7 years ago

Finally time zone come issue solve Thanks