问:
Invalid drawable tag vector on custom view
I created a custom view that takes an image icon, and I initialize it like this:

XML

IconFieldLinearLayout.java

```<code>private void initAttr(Context context, AttributeSet attrs) {

        if (attrs != null) {
            TypedArray a = context.obtainStyledAttributes(attrs,
                    R.styleable.IconFieldLinearLayout, 0, 0);

            Drawable icon = a.getDrawable(R.styleable.IconFieldLinearLayout_icon);
            boolean tintIcon = a.getBoolean(R.styleable.IconFieldLinearLayout_tintIcon, true);
            int color = a.getColor(R.styleable.IconFieldLinearLayout_tintColor, Color.WHITE);

            a.recycle();
            initIcon(context, icon, tintIcon, color);
        } else {
            initIcon(context, mDefaultDrawable, true, Color.WHITE);
        }
    }
</code>```

When I run this on Android 4.3 with this drawable:

```<code><vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#ffff"
        android:pathData="M12,5.9c1.16,0 2.1,0.94 2.1,2.1s-0.94,2.1 -2.1,2.1S9.9,9.16 9.9,8s0.94,-2.1 2.1,-2.1m0,9c2.97,0 6.1,1.46 6.1,2.1v1.1L5.9,18.1L5.9,17c0,-0.64 3.13,-2.1 6.1,-2.1M12,4C9.79,4 8,5.79 8,8s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,13c-2.67,0 -8,1.34 -8,4v3h16v-3c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>
</code>```

I get:

```android.view.InflateException: Binary XML file line #0: Error inflating class tv.myapp.ui.iconfield.IconFieldLinearLayout
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:669)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:745)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at tv.myapp.base.view.BaseMosbyFragment.onCreateView(BaseMosbyFragment.java:34)
                                                                                at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                                at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:540)
                                                                                at tv.myapp.login.LoginActivity$1.lambda$setResource$1$LoginActivity$1(LoginActivity.java:70)
                                                                                at tv.myapp.login.LoginActivity$1$$Lambda$1.run(Unknown Source)
                                                                                at android.os.Handler.handleCallback(Handler.java:730)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:177)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:643)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:745)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at tv.myapp.base.view.BaseMosbyFragment.onCreateView(BaseMosbyFragment.java:34)
                                                                                at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                                at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:540)
                                                                                at tv.myapp.login.LoginActivity$1.lambda$setResource$1$LoginActivity$1(LoginActivity.java:70)
                                                                                at tv.myapp.login.LoginActivity$1$$Lambda$1.run(Unknown Source)
                                                                                at android.os.Handler.handleCallback(Handler.java:730)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:177)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_person_outline.xml from drawable resource ID #0x7f0800db
                                                                                at android.content.res.Resources.loadDrawable(Resources.java:2974)
                                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.initAttr(IconFieldLinearLayout.java:59)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.init(IconFieldLinearLayout.java:51)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.<init>(IconFieldLinearLayout.java:34)
                                                                                at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:643)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:745)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at tv.myapp.base.view.BaseMosbyFragment.onCreateView(BaseMosbyFragment.java:34)
                                                                                at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                                at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:540)
                                                                                at tv.myapp.login.LoginActivity$1.lambda$setResource$1$LoginActivity$1(LoginActivity.java:70)
                                                                                at tv.myapp.login.LoginActivity$1$$Lambda$1.run(Unknown Source)
                                                                                at android.os.Handler.handleCallback(Handler.java:730)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:177)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #0: invalid drawable tag vector
                                                                                at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
                                                                                at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
                                                                                at android.content.res.Resources.loadDrawable(Resources.java:2970)
                                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.initAttr(IconFieldLinearLayout.java:59)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.init(IconFieldLinearLayout.java:51)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.<init>(IconFieldLinearLayout.java:34)
                                                                                at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:643)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:745)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at tv.myapp.base.view.BaseMosbyFragment.onCreateView(BaseMosbyFragment.java:34)
                                                                                at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                                at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:540)
                                                                                at tv.myapp.login.LoginActivity$1.lambda$setResource$1$LoginActivity$1(LoginActivity.java:70)
                                                                                at tv.myapp.login.LoginActivity$1$$Lambda$1.run(Unknown Source)
                                                                                at android.os.Handler.handleCallback(Handler.java:730)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:177)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                                                at dalvik.system.NativeStart.main(Native Method)
```

I have put vectorDrawables.useSupportLibrary = true on my gradle file.

答:
Replace this line:

```<code>Drawable icon = a.getDrawable(R.styleable.IconFieldLinearLayout_icon);
</code>```

with these:

```<code>int iconId = a.getResourceId(R.styleable.IconFieldLinearLayout_icon, 0);
Drawable icon = AppCompatResources.getDrawable(context, iconId);
</code>```

The AppCompatResources class will use VectorDrawableCompat to create the drawable if the resource is a <vector> and the platform is old enough that vector drawables aren't natively supported.

Body:
I created a custom view that takes an image icon, and I initialize it like this:

XML

IconFieldLinearLayout.java

private void initAttr(Context context, AttributeSet attrs) {

        if (attrs != null) {
            TypedArray a = context.obtainStyledAttributes(attrs,
                    R.styleable.IconFieldLinearLayout, 0, 0);

            Drawable icon = a.getDrawable(R.styleable.IconFieldLinearLayout_icon);
            boolean tintIcon = a.getBoolean(R.styleable.IconFieldLinearLayout_tintIcon, true);
            int color = a.getColor(R.styleable.IconFieldLinearLayout_tintColor, Color.WHITE);

            a.recycle();
            initIcon(context, icon, tintIcon, color);
        } else {
            initIcon(context, mDefaultDrawable, true, Color.WHITE);
        }
    }

When I run this on Android 4.3 with this drawable:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#ffff"
        android:pathData="M12,5.9c1.16,0 2.1,0.94 2.1,2.1s-0.94,2.1 -2.1,2.1S9.9,9.16 9.9,8s0.94,-2.1 2.1,-2.1m0,9c2.97,0 6.1,1.46 6.1,2.1v1.1L5.9,18.1L5.9,17c0,-0.64 3.13,-2.1 6.1,-2.1M12,4C9.79,4 8,5.79 8,8s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,13c-2.67,0 -8,1.34 -8,4v3h16v-3c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

I get:

android.view.InflateException: Binary XML file line #0: Error inflating class tv.myapp.ui.iconfield.IconFieldLinearLayout
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:669)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:745)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at tv.myapp.base.view.BaseMosbyFragment.onCreateView(BaseMosbyFragment.java:34)
                                                                                at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                                at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:540)
                                                                                at tv.myapp.login.LoginActivity$1.lambda$setResource$1$LoginActivity$1(LoginActivity.java:70)
                                                                                at tv.myapp.login.LoginActivity$1$$Lambda$1.run(Unknown Source)
                                                                                at android.os.Handler.handleCallback(Handler.java:730)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:177)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:643)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:745)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at tv.myapp.base.view.BaseMosbyFragment.onCreateView(BaseMosbyFragment.java:34)
                                                                                at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                                at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:540)
                                                                                at tv.myapp.login.LoginActivity$1.lambda$setResource$1$LoginActivity$1(LoginActivity.java:70)
                                                                                at tv.myapp.login.LoginActivity$1$$Lambda$1.run(Unknown Source)
                                                                                at android.os.Handler.handleCallback(Handler.java:730)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:177)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_person_outline.xml from drawable resource ID #0x7f0800db
                                                                                at android.content.res.Resources.loadDrawable(Resources.java:2974)
                                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.initAttr(IconFieldLinearLayout.java:59)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.init(IconFieldLinearLayout.java:51)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.<init>(IconFieldLinearLayout.java:34)
                                                                                at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:643)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:745)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at tv.myapp.base.view.BaseMosbyFragment.onCreateView(BaseMosbyFragment.java:34)
                                                                                at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                                at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:540)
                                                                                at tv.myapp.login.LoginActivity$1.lambda$setResource$1$LoginActivity$1(LoginActivity.java:70)
                                                                                at tv.myapp.login.LoginActivity$1$$Lambda$1.run(Unknown Source)
                                                                                at android.os.Handler.handleCallback(Handler.java:730)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:177)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #0: invalid drawable tag vector
                                                                                at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
                                                                                at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
                                                                                at android.content.res.Resources.loadDrawable(Resources.java:2970)
                                                                                at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.initAttr(IconFieldLinearLayout.java:59)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.init(IconFieldLinearLayout.java:51)
                                                                                at tv.myapp.ui.iconfield.IconFieldLinearLayout.<init>(IconFieldLinearLayout.java:34)
                                                                                at java.lang.reflect.Constructor.constructNative(Native Method)
                                                                                at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:643)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:745)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:804)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:526)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at tv.myapp.base.view.BaseMosbyFragment.onCreateView(BaseMosbyFragment.java:34)
                                                                                at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1984)
                                                                                at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:626)
                                                                                at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
                                                                                at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
                                                                                at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:540)
                                                                                at tv.myapp.login.LoginActivity$1.lambda$setResource$1$LoginActivity$1(LoginActivity.java:70)
                                                                                at tv.myapp.login.LoginActivity$1$$Lambda$1.run(Unknown Source)
                                                                                at android.os.Handler.handleCallback(Handler.java:730)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                at android.os.Looper.loop(Looper.java:177)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
                                                                                at dalvik.system.NativeStart.main(Native Method)

I have put vectorDrawables.useSupportLibrary = true on my gradle file.

Body:
Replace this line:

Drawable icon = a.getDrawable(R.styleable.IconFieldLinearLayout_icon);

with these:

int iconId = a.getResourceId(R.styleable.IconFieldLinearLayout_icon, 0);
Drawable icon = AppCompatResources.getDrawable(context, iconId);

The AppCompatResources class will use VectorDrawableCompat to create the drawable if the resource is a <vector> and the platform is old enough that vector drawables aren't natively supported.


来源: stackexchange

问:
jsonp is not firing beforeSend?
I am working on a project to call a webservice from different domain using $.ajax with dataType set to jsonp.

```<code>    $.ajax({
        type: "GET",
        url: testService.asmx,
        async: true,
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",

        beforeSend: function (XMLHttpRequest) {
            alert('Before Send'); //Nothing happnes
        },
        success: function (response) {
            alert('Success'); //this was fired
        },
        complete: function (XMLHttpRequest, textStatus) {
            alert('After Send'); //this was fired
        }
    });
</code>```

The problem is I have a ...loading animation which I want to display while the web service request is being processed. I tried using "beforeSend:" to show the loading animation but it seems like "beforeSend" is not getting fired.

The animation works fine when the app is on the same domain (using jsonp) but when I move the app into a different server, everything works except "beforeSend" is not getting called. So users will not be able to see the loading animation.

Is there any workaround for this?

答:
beforeSend implemention for jQuery JSONP is sill in progress.
The solution for now, use:

```<code>jQuery(document).ajaxStart(function(){alert('Before Send');}); // For all XHRs
$('#id').ajaxStart(function(){alert('Before Send');});         // For unique XHR
</code>```

before $.ajax({...});.

ContentLicense: CC BY-SA 2.5

Title: jsonp is not firing beforeSend?

Body:
I am working on a project to call a webservice from different domain using $.ajax with dataType set to jsonp.

    $.ajax({
        type: "GET",
        url: testService.asmx,
        async: true,
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",

        beforeSend: function (XMLHttpRequest) {
            alert('Before Send'); //Nothing happnes
        },
        success: function (response) {
            alert('Success'); //this was fired
        },
        complete: function (XMLHttpRequest, textStatus) {
            alert('After Send'); //this was fired
        }
    });

The problem is I have a ...loading animation which I want to display while the web service request is being processed. I tried using "beforeSend:" to show the loading animation but it seems like "beforeSend" is not getting fired.

The animation works fine when the app is on the same domain (using jsonp) but when I move the app into a different server, everything works except "beforeSend" is not getting called. So users will not be able to see the loading animation.

Is there any workaround for this?

Body:
beforeSend implemention for jQuery JSONP is sill in progress.
The solution for now, use:

jQuery(document).ajaxStart(function(){alert('Before Send');}); // For all XHRs
$('#id').ajaxStart(function(){alert('Before Send');});         // For unique XHR

before $.ajax({...});.


问:
Evaluate symbolic matrix in MATLAB
I defined 2 symbolic matrix in MATLAB, for example

```<code>w = sym('w',[10,10])
</code>```

Then I do some operations on it and get function E dependent to symbolic matrix w and v. Now, I want to evaluate E numerically with numerical w and v.

How can I do this?

答:
Simple example on R2017a:

```<code>>> syms E(v,w)
>> E(v,w) = v*w + v;
>> E(3,4)
ans =
    15
</code>```

On earlier versions, I believe symfun is the command to use.

ContentLicense: CC BY-SA 3.0

Title: Evaluate symbolic matrix in MATLAB

Body:
I defined 2 symbolic matrix in MATLAB, for example

w = sym('w',[10,10])

Then I do some operations on it and get function E dependent to symbolic matrix w and v. Now, I want to evaluate E numerically with numerical w and v.

How can I do this?

Body:
Simple example on R2017a:

>> syms E(v,w)
>> E(v,w) = v*w + v;
>> E(3,4)
ans =
    15

On earlier versions, I believe symfun is the command to use.


问:
Bootstrap editable table adding dynamic rows
I am working with bootstrap editable to create a dynamic table.
I need to add new row and automatically populate the values into the editable table.

The existing rows 'Test' are editable whereas , the new rows does not have the bootstrap editable properties.
I am using bootstrap-table-editable.js for the editable table.

Table HTML

```<code>             <table id="rules_table"
                      data-toggle="table">
                      <thead>
                         <tr>
                            <th data-editable="true" data-field="name" >Name</th>
                            <th data-editable="true" data-field="desc">Description</th>
                        </tr>
                      </thead>

                      <tr>
                        <td>Test</td>
                        <td>Test</td>
                      </tr>
              </table>
</code>```

jQuery

```<code>$('#add_rule').click(function()

 {
    var  name = $('#name').val()
    var desc= $('input[name=desc]:checked').val();

  $("#rules_table")
    .append($('<tr>')
    .append($('<td>')
            .text(rule_name)
            .append($('</td>'))
        )
        .append($('<td>')
            .text(rule_name)
            .append($('</td>'))
        )

       .append($('</tr>')
    ) )

 });
</code>```

The values 'name' and 'description' are getting added to the table. But it cannot be edited.

```<code><a href="javascript:void(0)" data-name="name" data-pk="undefined" data-value="Test" class="editable editable-click">Test</a>
</code>```

This is the html element contents from developer tools.

答:
Use contenteditable='true' attribute. (HTML5) </p>

```<code>$('#add_rule').click(function()

 {

  $("#rules_table")
    .append($('<tr>')
    .append($('<td contenteditable>')
            .text("rule_name")
            .append($('</td>'))
        )
        .append($('<td contenteditable>')
            .text("rule_name")
            .append($('</td>'))
        )

       .append($('</tr>')
    ) )

 });

    <button id="add_rule">
add</button>
</button>

    <table id="rules_table"
                          data-toggle="table">
                          <thead>
                             <tr>
                                <th data-editable="true" data-field="name" >Name</th>
                                <th data-editable="true" data-field="desc">Description</th>
                            </tr>
                          </thead>

                          <tr>
                            <td>Test</td>
                            <td>Test</td>
                          </tr>
                  </table>
</code>```

<p>Take help from this link </p>

Body:
I am working with bootstrap editable to create a dynamic table.
I need to add new row and automatically populate the values into the editable table.

The existing rows 'Test' are editable whereas , the new rows does not have the bootstrap editable properties.
I am using bootstrap-table-editable.js for the editable table.

Table HTML

                            Name
                            Description

                        Test
                        Test

jQuery

$('#add_rule').click(function()

 {
    var  name = $('#name').val()
    var desc= $('input[name=desc]:checked').val();

  $("#rules_table")
    .append($('
')
    .append($('')
            .text(rule_name)
            .append($('	'))
        )
        .append($('')
            .text(rule_name)
            .append($('	'))
        )

       .append($('
')
    ) )

 });

The values 'name' and 'description' are getting added to the table. But it cannot be edited.

Test

This is the html element contents from developer tools.

Body:
Use contenteditable='true' attribute. (HTML5)

$('#add_rule').click(function()

 {

  $("#rules_table")
    .append($('<tr>')
    .append($('<td contenteditable>')
            .text("rule_name")
            .append($('</td>'))
        )
        .append($('<td contenteditable>')
            .text("rule_name")
            .append($('</td>'))
        )

       .append($('</tr>')
    ) )

 });

    <button id="add_rule">
add</button>
</button>

    <table id="rules_table"
                          data-toggle="table">
                          <thead>
                             <tr>
                                <th data-editable="true" data-field="name" >Name</th>
                                <th data-editable="true" data-field="desc">Description</th>
                            </tr>
                          </thead>

                          <tr>
                            <td>Test</td>
                            <td>Test</td>
                          </tr>
                  </table>

Take help from this link


问:
compiling C code and C# code both into .NET DLL
I have a C# .NET DLL (call it CS_Code.dll) which is using

```<code>[DllImport("C_Code.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
</code>```

C_Code.dll contains mainly C code in extern "C" clauses.

When I will be using this assembly (CS_Code.dll) later in a project. I want to save from having to deliver two DLLs. All should be in one DLL.

Would it be possible to include (compile) the C-code into the .NET (e.g. as a library) making one .NET DLL out of it?

答:
You can create a mixed-mode assembly which contains both native and managed code, however it's quite a topic so I suggest you read the section about it here on MSDN:

Mixed (Native and Managed) Assemblies

Body:
I have a C# .NET DLL (call it CS_Code.dll) which is using

[DllImport("C_Code.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]

C_Code.dll contains mainly C code in extern "C" clauses.

When I will be using this assembly (CS_Code.dll) later in a project. I want to save from having to deliver two DLLs. All should be in one DLL.

Would it be possible to include (compile) the C-code into the .NET (e.g. as a library) making one .NET DLL out of it?


问:
Find all paths of length 2 in a graph
I've tried to create an algorithm for finding all paths of length 2, but it doesn't seem to work properly:

```<code>input_split = input().split(' ')
node_count = int(input_split[0])
input_count = int(input_split[1])
items = np.zeros((node_count, node_count), dtype=np.int32) # matrix of adjacency
for j in range(input_count):
    split = input().split(' ')
    x = int(split[0]) - 1 # convert 1 based coordinates to 0 based
    y = int(split[1]) - 1
    items[x][y] = 1
    items[y][x] = 1
result = np.linalg.matrix_power(items, 2)
result_sum = int(np.sum(result) / 2) # reverse paths are counted only once
print(result_sum)
</code>```

Sample input:

```<code>6 7
1 2
2 3
3 1
2 4
4 5
5 6
6 2
</code>```

The result should be 11, but it prints 18.

答:
You're on the right track when calculating the square of the adjacency matrix. After the exponentiation you would get result matrix that looks like this:

```<code>[[2 1 1 1 0 1]
 [1 4 1 0 2 0]
 [1 1 2 1 0 1]
 [1 0 1 2 0 2]
 [0 2 0 0 2 0]
 [1 0 1 2 0 2]]
</code>```

First you need to exclude all diagonal entries from this matrix, because those denote walks that are not paths, as their starting and ending node is the same. Note that for length 2 that is the only way how nodes can be repeating.

The other entries need to be counted only once, because of symmetry. So only look at the upper right triangle of the matrix.

One way to do it is:

```<code>result_sum = 0
for i in range(input_count - 1):
    for j in range(i + 1, input_count - 1):
        result_sum += result[i][j]
print(result_sum) # prints 11
</code>```

More Pythonic way, one-liner using numpy.trace():

```<code>result_sum = (np.sum(result) - np.trace(result)) // 2
</code>```

Title: Find all paths of length 2 in a graph

Body:
I've tried to create an algorithm for finding all paths of length 2, but it doesn't seem to work properly:

input_split = input().split(' ')
node_count = int(input_split[0])
input_count = int(input_split[1])
items = np.zeros((node_count, node_count), dtype=np.int32) # matrix of adjacency
for j in range(input_count):
    split = input().split(' ')
    x = int(split[0]) - 1 # convert 1 based coordinates to 0 based
    y = int(split[1]) - 1
    items[x][y] = 1
    items[y][x] = 1
result = np.linalg.matrix_power(items, 2)
result_sum = int(np.sum(result) / 2) # reverse paths are counted only once
print(result_sum)

Sample input:

6 7
1 2
2 3
3 1
2 4
4 5
5 6
6 2

The result should be 11, but it prints 18.

Body:
You're on the right track when calculating the square of the adjacency matrix. After the exponentiation you would get result matrix that looks like this:

[[2 1 1 1 0 1]
 [1 4 1 0 2 0]
 [1 1 2 1 0 1]
 [1 0 1 2 0 2]
 [0 2 0 0 2 0]
 [1 0 1 2 0 2]]

First you need to exclude all diagonal entries from this matrix, because those denote walks that are not paths, as their starting and ending node is the same. Note that for length 2 that is the only way how nodes can be repeating.

The other entries need to be counted only once, because of symmetry. So only look at the upper right triangle of the matrix.

One way to do it is:

result_sum = 0
for i in range(input_count - 1):
    for j in range(i + 1, input_count - 1):
        result_sum += result[i][j]
print(result_sum) # prints 11

More Pythonic way, one-liner using numpy.trace():

result_sum = (np.sum(result) - np.trace(result)) // 2


问:
Drools - Sliding window not working as expected
I'm new to drools.  I've defined the following rule to add the last two numbers in the stream together.  I then send in a stream of 100 events, with the values set from 1 to 100.  So I would expect the output to be 0, 1, 3, 5, 7, 9, 11, 13 etc.

```<code>declare TestEvent
     @role( event )
     value : int
end
rule "Simple Rule"
when
    $sum : Integer() from accumulate ( TestEvent( $value : value ) over window:length( 2 ); sum( $value)  )
then
    System.out.println("Value: " + $sum );
end
</code>```

The session is started using "fireUntilHalt" in a separate thread. If I put a delay of 10 milliseconds between every event inserted it works as expected.  However when I don't have the delay, the results aren't as expected.  Usually it just prints 0 and 197.  Sometimes I might get a number or two in-between as well.

Why does this happen and what I should do to fix?

答:
Ok, I finally understand it.
Having fireUntilHalt running in a separate thread means that the rules are only evaluated every now and then (not sure what that time period is).  My assumption was that they would be evaluated on every insert. So on every insert the accumulator values are updated, but the rules evaluated aren't evaluated. So because my rules are inserted quickly (in about one second), the first and last insert is all that seems to be evaluated.

To get this to work so every insert is evaluated, I removed the fireUntilHalt, and did a separate fireAllRules after each insert.

Body:
I'm new to drools.  I've defined the following rule to add the last two numbers in the stream together.  I then send in a stream of 100 events, with the values set from 1 to 100.  So I would expect the output to be 0, 1, 3, 5, 7, 9, 11, 13 etc.

declare TestEvent
     @role( event )
     value : int
end
rule "Simple Rule"
when
    $sum : Integer() from accumulate ( TestEvent( $value : value ) over window:length( 2 ); sum( $value)  )
then
    System.out.println("Value: " + $sum );
end

The session is started using "fireUntilHalt" in a separate thread. If I put a delay of 10 milliseconds between every event inserted it works as expected.  However when I don't have the delay, the results aren't as expected.  Usually it just prints 0 and 197.  Sometimes I might get a number or two in-between as well.

Why does this happen and what I should do to fix?


问:
Customer session is different in different parts of a Magento website
I have a function inside of a Helper in Magento that returns whether or not a customer attribute equals one.

Here is my Helper class

```<code>class Nie_Nie_Helper_Data extends Mage_Core_Helper_Abstract {
    public function isNieAdmin() {
        if(Mage::getSingleton('customer/session')->getCustomer()->getNieAdmin() == 1) {
            return true;
        } else {
            return false;
        }
    }
}
</code>```

Now when I call this function from a class that extends Mage_Core_Block_Template, everything seems to work fine. However when I try to use this inside one of my controllers, it does not work. In fact when I do Mage::getSingleton('customer/session')->getCustomer()->debug() the only variable that is returned is the website_id.

Does anyone know what I have to do in order to get this to work?

答:
Ok it looks like I had to load up the session myself. I had to put the following in my functions:

```<code>Mage::getSingleton('core/session', array('name' => 'frontend'));
</code>```

Hope this helps.

Body:
I have a function inside of a Helper in Magento that returns whether or not a customer attribute equals one.

Here is my Helper class

class Nie_Nie_Helper_Data extends Mage_Core_Helper_Abstract {
    public function isNieAdmin() {
        if(Mage::getSingleton('customer/session')->getCustomer()->getNieAdmin() == 1) {
            return true;
        } else {
            return false;
        }
    }
}

Now when I call this function from a class that extends Mage_Core_Block_Template, everything seems to work fine. However when I try to use this inside one of my controllers, it does not work. In fact when I do Mage::getSingleton('customer/session')->getCustomer()->debug() the only variable that is returned is the website_id.

Does anyone know what I have to do in order to get this to work?

Body:
Ok it looks like I had to load up the session myself. I had to put the following in my functions:

Mage::getSingleton('core/session', array('name' => 'frontend'));

Hope this helps.


问:
Django - collecting info per request
I want to collect data in each request (single request can cause several changes), and process the data at the end of the request.

So I'm using a singleton class to collect the data, and I'm processing the data in it on request_finished signal. Should it work or should I expect data loss/other issues?

singleton class:

```<code>class Singleton(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]

class DataManager(object, metaclass=Singleton):
     ....
</code>```

using it in other signal:

```<code>item_created = DataManager().ItemCreated(item)
DataManager().add_event_to_list(item_created)
</code>```

request finished signal:

```<code>@receiver(request_finished, dispatch_uid="request_finished")
def my_request_finished_handler(sender, **kwargs):
    DataManager().process_data()
</code>```

答:
A singleton means you have one single instance per process. Typical production Django setup is with one or more front server running multiple long running Django processes, each of one serving any incoming request. FWIW you could even serve Django in concurrent threads in a same process AFAICT. In this context, the same user can have subsequent requests served by different processes/threads, and any long-lived 'global' object will be shared by all requests served by the current process. The net result is, as Daniel Roseman rightly comments, that "Singletons will never do what you want in a multi-process multi-user environment like Django".

If you want to collect per-request-response cycle data, your best bet is to store them on the request object itself, using a middleware to initialize the collector on request processing cycle start and do something with collected data on request processing cycle end. This of course requires passing the request all along... which is indeed kind of clumsy.

A workaround here could be to connect some of your per-request "collector" object's methods as signal handlers, taking care of properly setting the "dispatch_uid" so you can disconnect them before sending the response, and preferably using weak references to avoid memory leaks.

NB : If you want to collect per-user informations, that's what the session framework is for, but I assume you already understood this.

Title: Django - collecting info per request

Body:
I want to collect data in each request (single request can cause several changes), and process the data at the end of the request.

So I'm using a singleton class to collect the data, and I'm processing the data in it on request_finished signal. Should it work or should I expect data loss/other issues?

singleton class:

class Singleton(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]

class DataManager(object, metaclass=Singleton):
     ....

using it in other signal:

item_created = DataManager().ItemCreated(item)
DataManager().add_event_to_list(item_created)

request finished signal:

@receiver(request_finished, dispatch_uid="request_finished")
def my_request_finished_handler(sender, **kwargs):
    DataManager().process_data()


问:
How to install latest version of nginx on raspbian?
What to specify in source.list? because when I write

```<code>deb http://nginx.org/packages/debian/ jessie nginx
deb-src http://nginx.org/packages/debian/ jessie nginx
</code>```

appears error:

```<code>Unable to find expected entry '' in Release file (Wrong sources.list entry or malformed file)
</code>```

答:
I followed @Joe's suggestion, it did not work in Raspbian Stretch

nginx:
  Installed: (none)
  Candidate: 1.10.3-1+deb9u1
  Version table:
     1.10.3-1+deb9u1 500
        500 http://mirrordirector.raspbian.org/raspbian stretch/main armhf Packages
     1.10.3-1+deb9u1~bpo8+2 100
        100 http://httpredir.debian.org/debian jessie-backports/main armhf Packages

Then I changed packages to refer to stretch backport and debian package instead of Ubuntu,

```<code># stretch-backports
deb http://httpredir.debian.org/debian/ stretch-backports main contrib non-free
deb-src http://httpredir.debian.org/debian/ stretch-backports main contrib non-free

# Nginx pre built packages
deb http://nginx.org/packages/mainline/debian/ stretch nginx
deb-src http://nginx.org/packages/mainline/debian/ stretch nginx
</code>```

The new one gives me

nginx:
  Installed: (none)
  Candidate: 1.13.3-1~bpo9+1
  Version table:
     1.13.3-1~bpo9+1 990
        990 http://httpredir.debian.org/debian stretch-backports/main armhf Packages
     1.10.3-1+deb9u1 500
        500 http://mirrordirector.raspbian.org/raspbian stretch/main armhf Packages

Body:
What to specify in source.list? because when I write

deb http://nginx.org/packages/debian/ jessie nginx
deb-src http://nginx.org/packages/debian/ jessie nginx

appears error:

Unable to find expected entry '' in Release file (Wrong sources.list entry or malformed file)

Body:
I followed @Joe's suggestion, it did not work in Raspbian Stretch

nginx:
  Installed: (none)
  Candidate: 1.10.3-1+deb9u1
  Version table:
     1.10.3-1+deb9u1 500
        500 http://mirrordirector.raspbian.org/raspbian stretch/main armhf Packages
     1.10.3-1+deb9u1~bpo8+2 100
        100 http://httpredir.debian.org/debian jessie-backports/main armhf Packages

Then I changed packages to refer to stretch backport and debian package instead of Ubuntu,

# stretch-backports
deb http://httpredir.debian.org/debian/ stretch-backports main contrib non-free
deb-src http://httpredir.debian.org/debian/ stretch-backports main contrib non-free

# Nginx pre built packages
deb http://nginx.org/packages/mainline/debian/ stretch nginx
deb-src http://nginx.org/packages/mainline/debian/ stretch nginx

The new one gives me

nginx:
  Installed: (none)
  Candidate: 1.13.3-1~bpo9+1
  Version table:
     1.13.3-1~bpo9+1 990
        990 http://httpredir.debian.org/debian stretch-backports/main armhf Packages
     1.10.3-1+deb9u1 500
        500 http://mirrordirector.raspbian.org/raspbian stretch/main armhf Packages


问:
-ear // .war //.POST_MODULE ERROR (java.lang.NoClassDefFoundError)
I'm in the process of migrating from JBOSS GA 5.1 to JBOSS EAP 6.4 and i have a problem loading the modules, i get this error:

```<code>Nuevas dependencias que faltan/no satisfechas:
service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations (faltan) dependientes: [service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.HandleDelegate, service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ValidatorFactory, service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ORB, service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.Validator]

    11:13:52,045 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014612: Operación ("deploy") falló - dirección: ([("deployment" => "SPM-GUI-ear.ear")]) - descripción de la falla: {
        "JBAS014671: Servicios fallidos" => {"jboss.deployment.subunit.\"SPM-GUI-ear.ear\".\"SPM-GUI.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"SPM-GUI-ear.ear\".\"SPM-GUI.war\".POST_MODULE: JBAS018733: Error al procesar la fase POST_MODULE de subdeployment \"SPM-GUI.war\" of deployment \"SPM-GUI-ear.ear\"
        Caused by: java.lang.NoClassDefFoundError: javax/faces/FacesException
        Caused by: java.lang.ClassNotFoundException: javax.faces.FacesException from [Module \"deployment.SPM-GUI-ear.ear:main\" from Service Module Loader]"},
        "JBAS014771: Servicios con dependencias que faltan/no disponibles" => [
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.HandleDelegate falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ValidatorFactory falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.ORB falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ORB falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.Validator falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.Validator falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.ValidatorFactory falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.HandleDelegate falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]"
        ]
    }
    ...
    ...
    ...
    11:13:52,045 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014612: Operación ("deploy") falló - dirección: ([("deployment" => "SPM-GUI-ear.ear")]) - descripción de la falla: {
        "JBAS014671: Servicios fallidos" => {"jboss.deployment.subunit.\"SPM-GUI-ear.ear\".\"SPM-GUI.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"SPM-GUI-ear.ear\".\"SPM-GUI.war\".POST_MODULE: JBAS018733: Error al procesar la fase POST_MODULE de subdeployment \"SPM-GUI.war\" of deployment \"SPM-GUI-ear.ear\"
        Caused by: java.lang.NoClassDefFoundError: javax/faces/FacesException
        Caused by: java.lang.ClassNotFoundException: javax.faces.FacesException from [Module \"deployment.SPM-GUI-ear.ear:main\" from Service Module Loader]"},
        "JBAS014771: Servicios con dependencias que faltan/no disponibles" => [
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.HandleDelegate falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ValidatorFactory falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.ORB falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ORB falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.Validator falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.Validator falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.ValidatorFactory falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.HandleDelegate falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]"
        ]
    }
</code>```

How can I fix that issue?

答:
It seems you are missing a dependency in your ear or in Jboss.

Add the jar containing javax/faces/FacesException class in your ear.

Two choices :

in the war : app-web.war/lib

in the ear : APP-INF\lib

How did you add this library before. In order to help you further you have to tell us how you generate your ear.

You can find it in javax.faces-api but you have to choose the right version for your ear. Example of maven dependency :

```<code><dependency>
  <groupId>javax.faces</groupId>
  <artifactId>javax.faces-api</artifactId>
</dependency>
</code>```

Body:
I'm in the process of migrating from JBOSS GA 5.1 to JBOSS EAP 6.4 and i have a problem loading the modules, i get this error:

Nuevas dependencias que faltan/no satisfechas:
service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations (faltan) dependientes: [service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.HandleDelegate, service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ValidatorFactory, service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ORB, service jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.Validator]

    11:13:52,045 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014612: Operación ("deploy") falló - dirección: ([("deployment" => "SPM-GUI-ear.ear")]) - descripción de la falla: {
        "JBAS014671: Servicios fallidos" => {"jboss.deployment.subunit.\"SPM-GUI-ear.ear\".\"SPM-GUI.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"SPM-GUI-ear.ear\".\"SPM-GUI.war\".POST_MODULE: JBAS018733: Error al procesar la fase POST_MODULE de subdeployment \"SPM-GUI.war\" of deployment \"SPM-GUI-ear.ear\"
        Caused by: java.lang.NoClassDefFoundError: javax/faces/FacesException
        Caused by: java.lang.ClassNotFoundException: javax.faces.FacesException from [Module \"deployment.SPM-GUI-ear.ear:main\" from Service Module Loader]"},
        "JBAS014771: Servicios con dependencias que faltan/no disponibles" => [
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.HandleDelegate falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ValidatorFactory falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.ORB falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ORB falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.Validator falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.Validator falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.ValidatorFactory falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.HandleDelegate falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]"
        ]
    }
    ...
    ...
    ...
    11:13:52,045 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014612: Operación ("deploy") falló - dirección: ([("deployment" => "SPM-GUI-ear.ear")]) - descripción de la falla: {
        "JBAS014671: Servicios fallidos" => {"jboss.deployment.subunit.\"SPM-GUI-ear.ear\".\"SPM-GUI.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"SPM-GUI-ear.ear\".\"SPM-GUI.war\".POST_MODULE: JBAS018733: Error al procesar la fase POST_MODULE de subdeployment \"SPM-GUI.war\" of deployment \"SPM-GUI-ear.ear\"
        Caused by: java.lang.NoClassDefFoundError: javax/faces/FacesException
        Caused by: java.lang.ClassNotFoundException: javax.faces.FacesException from [Module \"deployment.SPM-GUI-ear.ear:main\" from Service Module Loader]"},
        "JBAS014771: Servicios con dependencias que faltan/no disponibles" => [
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.HandleDelegate falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ValidatorFactory falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.ORB falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.ORB falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.Validator falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.Validator falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher.ValidatorFactory falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.TimerServiceDispatcher]",
            "jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations.HandleDelegate falta [jboss.naming.context.java.comp.SPM-GUI-ear.jboss-seam.EjbSynchronizations]"
        ]
    }

How can I fix that issue?

Body:
It seems you are missing a dependency in your ear or in Jboss.

Add the jar containing javax/faces/FacesException class in your ear.

Two choices :

in the war : app-web.war/lib

in the ear : APP-INF\lib

How did you add this library before. In order to help you further you have to tell us how you generate your ear.

You can find it in javax.faces-api but you have to choose the right version for your ear. Example of maven dependency :

<dependency>
  <groupId>javax.faces</groupId>
  <artifactId>javax.faces-api</artifactId>
</dependency>


答:
Have you tried using StandardScaler from sklearn ?

It has with_mean and with_std option, which you can use to get data you want.

Title: scaling data between -1 and 1 centred on zero

Body:
Apologies in advance for any incorrect wording. The reason I am not finding answers to this might be because I am not using the right terminology.

I have a dataframe that looks something like

0        -0.004973    0.008638   0.000264     -0.021122   -0.017193
1        -0.003744    0.008664   0.000423     -0.021031   -0.015688
2        -0.002526    0.008688   0.000581     -0.020937   -0.014195
3        -0.001322    0.008708   0.000740     -0.020840   -0.012715
4        -0.000131    0.008725   0.000898     -0.020741   -0.011249
5         0.001044    0.008738   0.001057     -0.020639   -0.009800
6         0.002203    0.008748   0.001215     -0.020535   -0.008368
7         0.003347    0.008755   0.001373     -0.020428   -0.006952
8         0.004476    0.008758   0.001531     -0.020319   -0.005554
9         0.005589    0.008758   0.001688     -0.020208   -0.004173
10        0.006687    0.008754   0.001845     -0.020094   -0.002809
...

For each column I would like to scale the data to a float between -1.0 and 1.0 for this column's min and max.

I have tried scikit learn's minmax scaler with scaler = MinMaxScaler(feature_range = (-1, 1)) but some values change sign as a result, which I need to preserve.

Is there a way to 'centre' the scaling on zero?


问:
Triggering a UITextField unwind segue by pressing Return: Why/How does this work?
In my current project I discovered that I could add an unwind segue to a UITextField and trigger the segue by pressing the return key if I also added an action to handle the didEndOnExit event. If the didEndOnExit handler is not connected to the event then the segue is not triggered.

I would like to understand this behavior. My interest stems from that there might be something for me to learn about how segues operate. On the other hand, the behavior might just be unique to UITextFields.

This simple GitHub project demonstrates the behavior.

Thank you for your attention.

答:
You have done a very unusual thing: you've attached a triggered segue to a text field, as its action segue. So the question is simply: what does that mean? In particular, what triggers a triggered segue attached to a text field? What is the "action" of a text field?

I mean, we know what triggers a triggered segue attached to a button: it's that the user taps the button. And we know what triggers a triggered segue attached to a table view cell: it's that the user selects the cell. But what about a text field? What must the user do to trigger its action segue?

The "unwind" business is a red herring, so let's eliminate it from our thinking. Delete the text field from the second view controller and put it in the first view controller. Hook the text field's action segue as a modal segue to the second view controller.

Now contemplate the text field in the first view controller. It behaves as you have described:

If we click in the text field and type and hit return, nothing happens.

If we add Did End On Exit to the text field and type and hit return, the keyboard is dismissed and we segue.

Well, think about that phrase "nothing happens" in the first bullet point. The keyboard is not dismissed! But dismissal of the keyboard is the text field's "action". There was no action. So there is no triggering of the action segue.

Now try this experiment: make the view controller the text field's delegate, and implement this method:

```<code>extension ViewController : UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
}
</code>```

Type in the text field and hit Return. The keyboard is dismissed and we segue to the next view controller. Dismissing the keyboard in response the Return key is the text field's action.

So you see, in a sense, both the unwind segue and the DidEndOnExit were red herrings, since I just accomplished the same thing without either of those. What matter is what the text field's Action is, and the triggering of its Action Segue in response.

Body:
You have done a very unusual thing: you've attached a triggered segue to a text field, as its action segue. So the question is simply: what does that mean? In particular, what triggers a triggered segue attached to a text field? What is the "action" of a text field?

I mean, we know what triggers a triggered segue attached to a button: it's that the user taps the button. And we know what triggers a triggered segue attached to a table view cell: it's that the user selects the cell. But what about a text field? What must the user do to trigger its action segue?

The "unwind" business is a red herring, so let's eliminate it from our thinking. Delete the text field from the second view controller and put it in the first view controller. Hook the text field's action segue as a modal segue to the second view controller.

Now contemplate the text field in the first view controller. It behaves as you have described:

If we click in the text field and type and hit return, nothing happens.

If we add Did End On Exit to the text field and type and hit return, the keyboard is dismissed and we segue.

Well, think about that phrase "nothing happens" in the first bullet point. The keyboard is not dismissed! But dismissal of the keyboard is the text field's "action". There was no action. So there is no triggering of the action segue.

Now try this experiment: make the view controller the text field's delegate, and implement this method:

extension ViewController : UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
}

Type in the text field and hit Return. The keyboard is dismissed and we segue to the next view controller. Dismissing the keyboard in response the Return key is the text field's action.

So you see, in a sense, both the unwind segue and the DidEndOnExit were red herrings, since I just accomplished the same thing without either of those. What matter is what the text field's Action is, and the triggering of its Action Segue in response.