Android Annotations, Parcelable object as Extra, producing IllegalArgumentException: is not a constant in android.text.Layout$Alignment

大兔子大兔子 提交于 2019-12-11 07:32:29

问题


I've got a class that is Parcelable and its data members are made up of Strings, Integers, Booleans, Dates, and other Parcelable objects which are made up of the same kinds of things. At the end of the tree though, it's only Strings, Integers, Booleans, and Dates (java.util.Date).

I have an @EActivity with an @Extra called entity that is one of these Parcelable objects.

I have an @EFragment with an @FragmentArg called entity as well. When I launch the Activity, I pass the entity along to the Activity and in onCreate the activity passes it along to the fragment.

However, I get this WEIRD exception that makes no sense:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/
com.my.app.NavControllerActivity_}: java.lang.IllegalArgumentException:
  is not a constant in android.text.Layout$Alignment

None of my values have anything to do with android.text.Layout, they are all just java.lang.String objects.

I'll put the entire stack trace below, but the point where it leaves my code is here in the NavControllerActivity_ code generated by android annotations:

private void injectExtras_() {
    Bundle extras_ = getIntent().getExtras();
    if (extras_!= null) {
        if (extras_.containsKey(ENTITY_EXTRA)) { // THIS CALL EVENTUALLY LEADS TO THE EXCEPTION
            this.entity = extras_.getParcelable(ENTITY_EXTRA);
        }
        if (extras_.containsKey(ROOT_FRAGMENT_CLASS_EXTRA)) {
            this.rootFragmentClass = ((Class) extras_.getSerializable(ROOT_FRAGMENT_CLASS_EXTRA));
        }
        if (extras_.containsKey(ROOT_FRAGMENT_NAME_EXTRA)) {
            this.rootFragmentName = extras_.getString(ROOT_FRAGMENT_NAME_EXTRA);
        }
    }
    setupViews();
}

Here is how I launch the activity:

NavControllerActivity_.intent(this)
    .rootFragmentClass(EditAnimalFragment_.class)
    .entity(entity)
    .start();

Here is the full stacktrace:

FATAL EXCEPTION: main
Process: com.my.app, PID: 30978
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.NavControllerActivity_}: java.lang.IllegalArgumentException:  is not a constant in android.text.Layout$Alignment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: java.lang.IllegalArgumentException:  is not a constant in android.text.Layout$Alignment
    at java.lang.Enum.valueOf(Enum.java:200)
    at android.text.Layout$Alignment.valueOf(Layout.java:2017)
    at android.text.style.AlignmentSpan$Standard.<init>(AlignmentSpan.java:33)
    at android.text.TextUtils$1.createFromParcel(TextUtils.java:711)
    at android.text.TextUtils$1.createFromParcel(TextUtils.java:689)
    at android.os.Parcel.readCharSequence(Parcel.java:1659)
    at android.os.Parcel.readValue(Parcel.java:2261)
    at android.os.Parcel.readArrayMapInternal(Parcel.java:2592)
    at android.os.BaseBundle.unparcel(BaseBundle.java:221)
    at android.os.BaseBundle.containsKey(BaseBundle.java:269)
    at com.my.app.NavControllerActivity_.injectExtras_(NavControllerActivity_.java:87)
    at com.my.app.NavControllerActivity_.init_(NavControllerActivity_.java:46)
    at com.my.app.NavControllerActivity_.onCreate(NavControllerActivity_.java:39)
    at android.app.Activity.performCreate(Activity.java:6237)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

回答1:


Thank you to @WonderCsabo for questioning my assumptions about my parcelling code and the objects being parceled. I made some code changes which fixed the problem and here's my assumption about what was really going wrong.

The error I made was in my Parcel in/out code. I was writing 20 fields to the Parcel, but when reading from the Parcel I was only reading 15 fields. Making sure my in-code matched my out-code made the problem go away.

I think what was happening is that since there was still data to unpack that it was screwing up another item that needed to get unpacked and throwing an exception that seemed unrelated.



来源:https://stackoverflow.com/questions/39553248/android-annotations-parcelable-object-as-extra-producing-illegalargumentexcept

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!