问:
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.

答:
```<code>public class MainActivity extends AppCompatActivity {
    static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }

    ...
}
</code>```

Please see this answer for more details

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:
public class MainActivity extends AppCompatActivity {
    static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }

    ...
}

Please see this answer for more details


来源: stackexchange

问:
Nested list using React
I am trying to create nested lists in separate div's using different input data. I am having a problem printing a nested list: List 2 here. I printing the name attribute of object and then checking if there are any childNodes print the name attribute of those too, nested that is. Here's the Parent class.

```<code>export default class Parent extends Component {
  render() {
    return (

    <div>
      <h4>List 1</h4>
      <ul>
        {this.props.jsonData1.map(item => {
          return <Child name={item.name}/>
        })}
      </ul>
    </div>

    <div>
      <h4>List 2</h4>
      <ul>
        {this.props.jsonData2.map(item1 => {
          return <Child name={item1.name}/>
         if(item1.childNodes){
           <ul>
           {item1.jsonData2.map(item2=>{
             return <Child name={item2.name}/>
           })}
         }</ul>
        })}
      </ul>
    </div>
    );
  }
}
</code>```

My Child class is pretty simple. It only returns a single list element.

```<code>export default class Child extends Component {
  render() {
    let {name}=this.props;
    return (
      <li>{name}</li>
    );
  }
}
</code>```

I would appreciate some guidance about what I am doing wrong here. I am trying to keep the recursion as simple as possible but apparently I am doing it wrong.

答:
You're almost there, but maybe this will guide you to the right track. Whenever we want to do something recursively, we want to know what our base case would be for us to not call the function again. So in my little example and using what you've got.

```<code>export default class Child extends Component {
  render() {
    let {name}=this.props;
    return (
      <li>{name}</li>
    );
  }
}
</code>```

Our base case is if child.childNodes exist, then we want to create a new
 element list. However if it doesn't exist but the item exists, then we want to just render the
. this will keep going until there isn't anymore child nodes or items.

```<code>export default class Parent extends Component {
  renderChild = (child) => {
    if (child.childNodes) {
      return (
        <ul>
          {child.jsonData.map(item => {
            return this.renderChild(item);
          })}
        </ul>
      );
    }
    else if (child.name) {
     return <Child name={child.name}/>;
    }
    return null;
   }

  render() {
    return (
    <div>
      <h4>Nested Lists</h4>
      <ul>
        {this.renderChild(this.props.jsonData)}
      </ul>
    </div>
  );
}
</code>```

ContentLicense: CC BY-SA 3.0

Title: Nested list using React

Body:
I am trying to create nested lists in separate div's using different input data. I am having a problem printing a nested list: List 2 here. I printing the name attribute of object and then checking if there are any childNodes print the name attribute of those too, nested that is. Here's the Parent class.

export default class Parent extends Component {
  render() {
    return (

List 1

        {this.props.jsonData1.map(item => {
          return <Child name={item.name}/>
        })}

List 2

        {this.props.jsonData2.map(item1 => {
          return <Child name={item1.name}/>
         if(item1.childNodes){

           {item1.jsonData2.map(item2=>{
             return <Child name={item2.name}/>
           })}
         }

        })}

    );
  }
}

My Child class is pretty simple. It only returns a single list element.

export default class Child extends Component {
  render() {
    let {name}=this.props;
    return (

{name}

    );
  }
}

I would appreciate some guidance about what I am doing wrong here. I am trying to keep the recursion as simple as possible but apparently I am doing it wrong.

Body:
You're almost there, but maybe this will guide you to the right track. Whenever we want to do something recursively, we want to know what our base case would be for us to not call the function again. So in my little example and using what you've got.

export default class Child extends Component {
  render() {
    let {name}=this.props;
    return (
      <li>{name}</li>
    );
  }
}

Our base case is if child.childNodes exist, then we want to create a new <ul> element list. However if it doesn't exist but the item exists, then we want to just render the <li>. this will keep going until there isn't anymore child nodes or items.

export default class Parent extends Component {
  renderChild = (child) => {
    if (child.childNodes) {
      return (
        <ul>
          {child.jsonData.map(item => {
            return this.renderChild(item);
          })}
        </ul>
      );
    }
    else if (child.name) {
     return <Child name={child.name}/>;
    }
    return null;
   }

  render() {
    return (
    <div>
      <h4>Nested Lists</h4>
      <ul>
        {this.renderChild(this.props.jsonData)}
      </ul>
    </div>
  );
}


问:
What kind of languages do Deep Neural Network models of Microsoft Translate Text API cover?
I am surveying Microsoft Translate Text API.
I learned that it has two type of translator model, newer Deep Neural Network model, DNN, and traditional Statistical Machine Translation, SMT.

I also found the following instruction,

```<code>Microsoft Translator supports 60 languages for text translation through the Microsoft Translator API.
</code>```

However, I could not find how may languages the DNN model covers.
Does DNN model cover 60 langues all?
please tell me it.

答:
Yes the and is indeed important. Please know more languages will be added soon to the list below: The following neural network models are available for all speech languages through the Microsoft Translator Speech API and through the Translator text API (plus the Korean text language) by using the ”generalnn” category ID:
Arabic,
Chinese (Mandarin),
English,
French,
German,
Italian,
Japanese,
Korean,
Portuguese,
Russian,
Spanish,
The list is updated regularly, and you can find it here: https://www.microsoft.com/en-us/translator/languages.aspx

Body:
I am surveying Microsoft Translate Text API.
I learned that it has two type of translator model, newer Deep Neural Network model, DNN, and traditional Statistical Machine Translation, SMT.

I also found the following instruction,

Microsoft Translator supports 60 languages for text translation through the Microsoft Translator API.

However, I could not find how may languages the DNN model covers.
Does DNN model cover 60 langues all?
please tell me it.


问:
How to correctly malloc a struct in C
Here is my full code, it looks like to work, but it's not working very well.
I would accept any code, that is working like this.

Firstly, the code works, but when I want to add the third name to the struct, it crashes.

Is there any other way to do this?

I need struct, because in the future, I want to add some other params, like age, average, gender, etc.

Please, help me out.

```<code>//The student table
typedef struct students {
    char name[50];
} students;

//Global params
int scount = 0;
students *s;

//Basic functions
void addNewStudent();

int main()
{
    int loop = 1;
    char in;
    int ch;
    printf("Willkommen.\n Wahlen Sie bitte von die folgenden Optionen:\n");
    while (loop)
    {
        printf("\t[1] Neue Student eingeben\n");
        printf("\t[9] Programm beenden\n");

        scanf(" %c", &in);
        while ((ch = getchar()) != '\n');
        switch (in)
        {
        case '1':
            addNewStudent();
            break;
        case '9':
            loop = 0;
            break;
        default: printf("------\nOption nicht gefunden.\n------\n");
            break;
        }
    }
    free(s);
    return 0;
}

void addNewStudent()
{
    int index = 0;
    if (scount == 0)
    {
        s = (students*)malloc(sizeof(students));
    }
    else
    {
        realloc(s, sizeof(students) * scount);
    }

    printf("Geben Sie Bitte die Name:\n");
    fgets(s[scount].name, sizeof(s[scount].name), stdin);

    while (s[scount].name[index] != '\n')
    {
        index++;
    }
    s[scount].name[index] = '\0';
    scount++;
}
</code>```

I'm using Visual Studio.

Thanks for help!

答:
realloc returns a new pointer that you need to keep:

```<code>  students* snew = realloc(s, sizeof(students) * (scount + 1));
  if (!snew) {
     free(s); // If there is not enough memory, the old memory block is not freed
     // handle out of memory
  } else {
     s = snew;
  }
</code>```

Title: How to correctly malloc a struct in C

Body:
Here is my full code, it looks like to work, but it's not working very well.
I would accept any code, that is working like this.

Firstly, the code works, but when I want to add the third name to the struct, it crashes.

Is there any other way to do this?

I need struct, because in the future, I want to add some other params, like age, average, gender, etc.

Please, help me out.

//The student table
typedef struct students {
    char name[50];
} students;

//Global params
int scount = 0;
students *s;

//Basic functions
void addNewStudent();

int main()
{
    int loop = 1;
    char in;
    int ch;
    printf("Willkommen.\n Wahlen Sie bitte von die folgenden Optionen:\n");
    while (loop)
    {
        printf("\t[1] Neue Student eingeben\n");
        printf("\t[9] Programm beenden\n");

        scanf(" %c", &in);
        while ((ch = getchar()) != '\n');
        switch (in)
        {
        case '1':
            addNewStudent();
            break;
        case '9':
            loop = 0;
            break;
        default: printf("------\nOption nicht gefunden.\n------\n");
            break;
        }
    }
    free(s);
    return 0;
}

void addNewStudent()
{
    int index = 0;
    if (scount == 0)
    {
        s = (students*)malloc(sizeof(students));
    }
    else
    {
        realloc(s, sizeof(students) * scount);
    }

    printf("Geben Sie Bitte die Name:\n");
    fgets(s[scount].name, sizeof(s[scount].name), stdin);

    while (s[scount].name[index] != '\n')
    {
        index++;
    }
    s[scount].name[index] = '\0';
    scount++;
}

I'm using Visual Studio.

Thanks for help!

Body:
realloc returns a new pointer that you need to keep:

  students* snew = realloc(s, sizeof(students) * (scount + 1));
  if (!snew) {
     free(s); // If there is not enough memory, the old memory block is not freed
     // handle out of memory
  } else {
     s = snew;
  }


问:
GitLab CI build fails with git is not recognized
I have set up a GitLab pipeline, and configured a runner. The build starts when I make a commit, but fails almost immediately with the following message:

```<code>C:\GitLabRunner\builds\xxxxxxxx\0\cmac\portal>"git" "checkout" "-f" "-q"
   "xxxxxxxxxxxxxxxxxxxxxxxxx"

 '"git"' is not recognized as an internal or external command,
   operable program or batch file.

C:\GitLabRunner>IF 9009 NEQ 0 exit /b 9009
ERROR: Job failed: exit status 9009
</code>```

This is my .gitlab-ci.yml, which I have stripped right back to try and isolate the issue:

```<code>stages:
 - build
variables:
  CI_DEBUG_TRACE: "true"
Build:
  stage: build
  script:
     - Echo OK
</code>```

The only similar issues I could find are here and here

I thought I had fixed the issue when I was getting the same message in a when trying to use git in a standard command prompt as my PATH wasn't set correctly in Environment variables.

However I have now fixed this and I am getting expected responses back from git through the command prompt, however I still get the issue when gitlab kicks off the build.

Any ideas?

答: After you install new applications on your buildmachine restart gitlab runner to pick up path.</p>

Body:
I have set up a GitLab pipeline, and configured a runner. The build starts when I make a commit, but fails almost immediately with the following message:

C:\GitLabRunner\builds\xxxxxxxx\0\cmac\portal>"git" "checkout" "-f" "-q"
   "xxxxxxxxxxxxxxxxxxxxxxxxx"

 '"git"' is not recognized as an internal or external command,
   operable program or batch file.

C:\GitLabRunner>IF 9009 NEQ 0 exit /b 9009
ERROR: Job failed: exit status 9009

This is my .gitlab-ci.yml, which I have stripped right back to try and isolate the issue:

stages:
 - build
variables:
  CI_DEBUG_TRACE: "true"
Build:
  stage: build
  script:
     - Echo OK

The only similar issues I could find are here and here

I thought I had fixed the issue when I was getting the same message in a when trying to use git in a standard command prompt as my PATH wasn't set correctly in Environment variables.

However I have now fixed this and I am getting expected responses back from git through the command prompt, however I still get the issue when gitlab kicks off the build.

Any ideas?


问:
Spring Boot REST Controller returns 404 when deployed on external tomcat 9 server
I have a spring boot rest web application which works perfectly on the embedded server. However after following the steps mentioned in the is blog https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file, I got a 404 error message whan I send a resquest to a resource on the server.I have used java 1.8.0_212 locally and used java 1.8.0_131 and deployed my app on tomcat 9 on the server. One thing that's puzzling me is that the repositories which extends CrudRepository can be accessed. Below is my application's entry point.

```<code>@SpringBootApplication
@ComponentScan(basePackages = "com.dbe.ref")
public class RefmsApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(RefmsApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(RefmsApplication.class, args);
    }
</code>```

and also my pom.xml

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.dbe.ref</groupId>
    <artifactId>refms</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>refms</name>
    <description>project for Rural electrification fund</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>LATEST</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <start-class>com.RefmsApplication</start-class>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>2.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>angularjs</artifactId>
            <version>1.4.10</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.4</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>font-awesome</artifactId>
            <version>4.7.0</version>
        </dependency>
        <dependency>
            <groupId>eu.michael-simons</groupId>
            <artifactId>wro4j-spring-boot-starter</artifactId>
            <version>0.3.4</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.14</version>
        </dependency>

        <dependency>
            <groupId>net.sourceforge.dynamicreports</groupId>
            <artifactId>dynamicreports-core</artifactId>
            <version>5.0.0</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>refms</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
</code>```

Here is part of the log:

```<code>2017-09-19 10:38:20.564  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'errorPageFilter' to: [/*]
2017-09-19 10:38:20.565  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-09-19 10:38:20.566  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-09-19 10:38:20.568  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-19 10:38:20.568  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-09-19 10:38:20.571  INFO 6660 --- [           main] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2017-09-19 10:38:20.571  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'configurableWroFilter' to urls: [/wro4j/*]
2017-09-19 10:38:20.572  INFO 6660 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServletRegistration' to [/refms/*]
2017-09-19 10:38:20.573  INFO 6660 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
</code>```

答:
Check if the

```<code><build>
     <finalName>refms</finalName>
         ...
</build>
</code>```

in the pom.xml corresponds with the

```<code>server.contextPath=/refms
</code>```

in the application.properties and check the

```<code><Context path="/refms"/>
</code>```

in the context.xml. Perhaps your root context in tomcat
after deploy was different.

Additionally, change this dependence

```<code><dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
</code>```

by this

```<code><dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
</code>```

for external tomcat

Body:
I have a spring boot rest web application which works perfectly on the embedded server. However after following the steps mentioned in the is blog https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file, I got a 404 error message whan I send a resquest to a resource on the server.I have used java 1.8.0_212 locally and used java 1.8.0_131 and deployed my app on tomcat 9 on the server. One thing that's puzzling me is that the repositories which extends CrudRepository can be accessed. Below is my application's entry point.

@SpringBootApplication
@ComponentScan(basePackages = "com.dbe.ref")
public class RefmsApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(RefmsApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(RefmsApplication.class, args);
    }

and also my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.dbe.ref</groupId>
    <artifactId>refms</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>refms</name>
    <description>project for Rural electrification fund</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>LATEST</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <start-class>com.RefmsApplication</start-class>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>2.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>angularjs</artifactId>
            <version>1.4.10</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.4</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>font-awesome</artifactId>
            <version>4.7.0</version>
        </dependency>
        <dependency>
            <groupId>eu.michael-simons</groupId>
            <artifactId>wro4j-spring-boot-starter</artifactId>
            <version>0.3.4</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.14</version>
        </dependency>

        <dependency>
            <groupId>net.sourceforge.dynamicreports</groupId>
            <artifactId>dynamicreports-core</artifactId>
            <version>5.0.0</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>refms</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Here is part of the log:

2017-09-19 10:38:20.564  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'errorPageFilter' to: [/*]
2017-09-19 10:38:20.565  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-09-19 10:38:20.566  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-09-19 10:38:20.568  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-19 10:38:20.568  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-09-19 10:38:20.571  INFO 6660 --- [           main] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2017-09-19 10:38:20.571  INFO 6660 --- [           main] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'configurableWroFilter' to urls: [/wro4j/*]
2017-09-19 10:38:20.572  INFO 6660 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServletRegistration' to [/refms/*]
2017-09-19 10:38:20.573  INFO 6660 --- [           main] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]

Body:
Check if the

<build>
     <finalName>refms</finalName>
         ...
</build>

in the pom.xml corresponds with the

server.contextPath=/refms

in the application.properties and check the

<Context path="/refms"/>

in the context.xml. Perhaps your root context in tomcat
after deploy was different.

Additionally, change this dependence

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

by this

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

for external tomcat


问:
Regular expression for alphanumeric and underscores
Is there a regular expression which checks if a string contains only upper and lowercase letters, numbers, and underscores?</p>

答:
^\w*$ will work for the below combinations:

```<code>1
123
1av
pRo
av1
</code>```

OwnerDisplayName: Jim

ContentLicense: CC BY-SA 4.0

Body:
^\w*$ will work for the below combinations:

1
123
1av
pRo
av1


问:
Angular router outlet automatically activating
In the parent view I have a mat-button-toggle-group to switch between a grid and list layout. The grid layout uses the router-outlet to display the child-component <router-outlet></router-outlet>, but the list layout implements the child component directly using the selector <child-view [child]="childItem"></child-view>.

Both gird and list html are in the same parent html file but are displayed by checking the viewStyle variable. When the mat-button-toggle-group button is pressed the new viewStyle is set and passed as a query param; the route is navigated back to the original parent view with no params, only query params - this.router.navigate([this.parentName],{ queryParams: { viewStyle: this.viewStyle }});.

So in the grid view, when you click on a child element, it activates the router link and displays information correctly. Then if you click on the list view it will deactivate the router link and switch correctly. The problem is when you click back to the grid link, the router outlet automatically activates and the last child to be selected is show in the display.

Is there a way to reset the router outlet when the viewStyle changes or are there other ways to route the page?

EDIT:
An organization (parent) has multiple repositories (child)...I want to display repos in grid and list views. When you click on a repo in the grid view it displays information on the right and adds the repo name to the url. The list view is just mat-expansion-panels, when you click on one it expands with the repository-view selector component.

routes

```<code>const appRoutes: Routes = [
  {
    path: ':orgName',
    component: OrganizationViewComponent,
    children:[
      {
        path: ':repoName',
        component: RepositoryViewComponent,
      },
    ],
  },
];
</code>```

HTML

```<code><mat-button-toggle-group (change)="viewChange($event)" [value]="viewStyle">
  <mat-button-toggle value="grid">Grid View</mat-button-toggle>
  <mat-button-toggle value="list">List View</mat-button-toggle>
</mat-button-toggle-group>

<div *ngIf="viewStyle==='grid'">
  <div class="org-grid-view-content">
    <h3>Repositories for {{orgName}}</h3>
    <span *ngFor="let repo of repos">
      <mat-card class="col-sm-1 repo-label" (click)="displayRepoView(repo)" [routerLink]="[repo.name]" [queryParams]="getQueryParams()" *ngIf="shouldShowRepo(repo)"
  [ngClass]="applyClasses(repo)">
      <!-- mat-card-information -->
      </mat-card>
    </span>
  </div>

  <div class="repo-view-container">
    <h3 *ngIf="currentrepo">Pull Requests for {{currentrepo.name}} repository</h3>
    <h3 *ngIf="!currentrepo">Select a repository to view pull request and status details</h3>
    <p>sort and search options</p>
    <router-outlet</router-outlet>
  </div>
</div>

<div *ngIf="viewStyle==='list'">
  <div class="org-list-view-content">
    <h3>Repositories</h3>
    <span *ngFor="let repo of repos">
      <mat-expansion-panel>
        <repository-view
        [repo]="repo">
        </repository-view>
      </<mat-expansion-panel>
    </span>
  </div>
</div>
</code>```

component.ts

```<code>viewChange(event: any) {
    this.viewStyle = event.value;
    this.openRepos = [];
    this.currentrepo = null;
    this.router.navigate([this.orgName, {
      outlets: { primary: null }
    }], { queryParams: this.getQueryParams() })
  }
</code>```

答:
Try this

```<code>this.router.navigate([this.parentName, {
  outlets: {
    primary: null
  }
}], { queryParams: { viewStyle: this.viewStyle } })
</code>```

Angular - clearing secondary routes

Body:
In the parent view I have a mat-button-toggle-group to switch between a grid and list layout. The grid layout uses the router-outlet to display the child-component <router-outlet></router-outlet>, but the list layout implements the child component directly using the selector <child-view [child]="childItem"></child-view>.

Both gird and list html are in the same parent html file but are displayed by checking the viewStyle variable. When the mat-button-toggle-group button is pressed the new viewStyle is set and passed as a query param; the route is navigated back to the original parent view with no params, only query params - this.router.navigate([this.parentName],{ queryParams: { viewStyle: this.viewStyle }});.

So in the grid view, when you click on a child element, it activates the router link and displays information correctly. Then if you click on the list view it will deactivate the router link and switch correctly. The problem is when you click back to the grid link, the router outlet automatically activates and the last child to be selected is show in the display.

Is there a way to reset the router outlet when the viewStyle changes or are there other ways to route the page?

EDIT:
An organization (parent) has multiple repositories (child)...I want to display repos in grid and list views. When you click on a repo in the grid view it displays information on the right and adds the repo name to the url. The list view is just mat-expansion-panels, when you click on one it expands with the repository-view selector component.

routes

const appRoutes: Routes = [
  {
    path: ':orgName',
    component: OrganizationViewComponent,
    children:[
      {
        path: ':repoName',
        component: RepositoryViewComponent,
      },
    ],
  },
];

HTML

<mat-button-toggle-group (change)="viewChange($event)" [value]="viewStyle">
  <mat-button-toggle value="grid">Grid View</mat-button-toggle>
  <mat-button-toggle value="list">List View</mat-button-toggle>
</mat-button-toggle-group>

Repositories for {{orgName}}

      <mat-card class="col-sm-1 repo-label" (click)="displayRepoView(repo)" [routerLink]="[repo.name]" [queryParams]="getQueryParams()" *ngIf="shouldShowRepo(repo)"
  [ngClass]="applyClasses(repo)">

      </mat-card>

Pull Requests for {{currentrepo.name}} repository

Select a repository to view pull request and status details

sort and search options

    <router-outlet</router-outlet>

Repositories

      <mat-expansion-panel>
        <repository-view
        [repo]="repo">
        </repository-view>
      </<mat-expansion-panel>

component.ts

viewChange(event: any) {
    this.viewStyle = event.value;
    this.openRepos = [];
    this.currentrepo = null;
    this.router.navigate([this.orgName, {
      outlets: { primary: null }
    }], { queryParams: this.getQueryParams() })
  }

Body:
Try this

this.router.navigate([this.parentName, {
  outlets: {
    primary: null
  }
}], { queryParams: { viewStyle: this.viewStyle } })

Angular - clearing secondary routes


问:
SAP B1 9.1 Open sales order Quantity query
I need to have a query where i can see open sales order quantity (PO and In stock) but i need to see based on customer reference. i have a customer who many stores. and his order # joins a store #. so under every order there can be 100 stores at a time. Against every store there is a sales order in SAP B1 9.1 having referece like 818201-3001(PO# -Store#) so that goods can be ship according to store address. Splitting "NUMATCARD" and consolidating quantity at store level is beyond my approach.

I need to have a query which show results as attached output sheet.

答:
I have this query but couldn't translate CustomerRef into rows and columns.</p>

```<code>SELECT T0.[DocDueDate],
    T0.[CardName],
    T0.[NumAtCard],
    T0.[DocNum],
    T1.[ItemCode],
    T1.[Dscription],
    T3.[WhsCode],
    T3.[OnHand] - SUM(OpenQty) OVER (Partition By T1.ItemCode ORDER BY DocDueDate, LineNum, NumAtCard, DocNum) + SUM(T1.OpenQty) AS 'Available',
    SUM(T1.[Quantity]) AS 'PO QTY',
    SUM(T1.OpenQty) AS 'To Release'
FROM
    ORDR T0
    INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry]
    INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode]
    INNER JOIN OITW T3 ON T2.[ItemCode] = T3.[ItemCode] AND T1.[WhsCode] = T3.[WhsCode]
WHERE
    T0.[CardCode] = 'c00192' and
    T0.[DocStatus] = 'O' AND
    T1.[LineStatus] = 'O' AND
    T0.[CANCELED] = 'N' AND
    T1.[WhsCode] = '161'
GROUP BY
    T0.[DocDueDate],
    T0.[CardName],
    T0.[NumAtCard],
    T0.[DocNum],
    T1.[ItemCode],
    T1.[Dscription],
    T3.[OnHand],
    T3.[WhsCode],
    T1.[LineNum],
    T1.OpenQty
ORDER BY
    T0.[DocDueDate],
    T0.[NumAtCard],
    T0.[DocNum]
</code>```

Body:
I have this query but couldn't translate CustomerRef into rows and columns.

SELECT T0.[DocDueDate],
    T0.[CardName],
    T0.[NumAtCard],
    T0.[DocNum],
    T1.[ItemCode],
    T1.[Dscription],
    T3.[WhsCode],
    T3.[OnHand] - SUM(OpenQty) OVER (Partition By T1.ItemCode ORDER BY DocDueDate, LineNum, NumAtCard, DocNum) + SUM(T1.OpenQty) AS 'Available',
    SUM(T1.[Quantity]) AS 'PO QTY',
    SUM(T1.OpenQty) AS 'To Release'
FROM
    ORDR T0
    INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry]
    INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode]
    INNER JOIN OITW T3 ON T2.[ItemCode] = T3.[ItemCode] AND T1.[WhsCode] = T3.[WhsCode]
WHERE
    T0.[CardCode] = 'c00192' and
    T0.[DocStatus] = 'O' AND
    T1.[LineStatus] = 'O' AND
    T0.[CANCELED] = 'N' AND
    T1.[WhsCode] = '161'
GROUP BY
    T0.[DocDueDate],
    T0.[CardName],
    T0.[NumAtCard],
    T0.[DocNum],
    T1.[ItemCode],
    T1.[Dscription],
    T3.[OnHand],
    T3.[WhsCode],
    T1.[LineNum],
    T1.OpenQty
ORDER BY
    T0.[DocDueDate],
    T0.[NumAtCard],
    T0.[DocNum]


问:
Mercurial: Indicating that a branch has passed testing?
I am working on establishing a workflow at my company if we were to migrate to DVCS (most likely Mercurial).  One of the things I would like to do is to have a repository for QA.  The idea being that each developer works on a branch and when they are done the branch is pushed to QA.  From there the test team can do their testing and report back any bugs.  Once the branch is fully tested and acceptable it will be pushed to a staging repository where the merge back to the mainline will happen before pushing to the central repository.

This can work quite easily if everyone just communicates the status of their work in some way, but I know this doesn't always happen as you would want it to.  What I am worried about is branches in the QA repo waiting around but nobody knows if it is waiting to be tested, currently being tested, waiting for fixes, waiting to be pushed to the staging area etc.  So what I am looking for are ideas of how a status can be added to a branch?  What would also be good would be to do it in a way that we could use hooks to also notify people of changes in the status.

Any ideas would be appreciated.

答:
One simple method might be to keep a metadata file in your repo's root folder, named .teststatus or somesuch, that looks like:

```<code># branch-name, last passed revision
default, 0123456789ab
stable, 0123456789ac
bobs-dev-branch, 0123456789ad
marys-dev-branch, none
</code>```

Using tags or bookmarks would feel like a sort of abuse, here. You couldn't use the same tag across branches (e.g. passed would have to be stable-passed), and tags are generally not moving. Bookmarks, on the other hand, are intended to move, but you still have the branch-namespacing issues.

ContentLicense: CC BY-SA 2.5

Body:
One simple method might be to keep a metadata file in your repo's root folder, named .teststatus or somesuch, that looks like:

# branch-name, last passed revision
default, 0123456789ab
stable, 0123456789ac
bobs-dev-branch, 0123456789ad
marys-dev-branch, none

Using tags or bookmarks would feel like a sort of abuse, here. You couldn't use the same tag across branches (e.g. passed would have to be stable-passed), and tags are generally not moving. Bookmarks, on the other hand, are intended to move, but you still have the branch-namespacing issues.


问:
Matlab unique cell combinations
I have a list as given below:

```<code>A= {[1 2], [2 1], [2 1 3],[3 4],[4 3]}
</code>```

I need to simplify the matrix. For example, [3 4] and [4 3] form the same combination, only one of them is enough. Also, [1 2] and [2 1] is the same combinations, so I should be left with

```<code>newA= {[1 2],[2 1 3],[3 4]}
</code>```

How do I do that?

答:
Here is a solution using accumarray:

```<code>n = cellfun(@numel,A);
C=accumarray(n(:),1:numel(A),[],@(x){num2cell(unique(sort(vertcat(A{x}),2),'rows'),2)});
result = vertcat(C{~cellfun(@isempty,C)})
</code>```

I tested 3 proposed answers with the following data in Octave:

```<code>A=arrayfun(@(x){randi([1 10],1,randi([1 10000]))},1:50);
</code>```

Here is the result:

```<code>======NUM2STR=======:
Elapsed time is 1.13129 seconds.
======FOR LOOP=======:
Elapsed time is 0.237398 seconds.
======ACCUMARRAY=======:
Elapsed time is 0.036804 seconds.
</code>```

With the following data:

```<code>A=arrayfun(@(x){randi([1 3],1,randi([1 5]))},1:500);
</code>```

Result:

```<code>======NUM2STR=======:
Elapsed time is 0.384026 seconds.
======FOR LOOP=======:
Elapsed time is 10.9931 seconds.
======ACCUMARRAY=======:
Elapsed time is 0.0271118 seconds.
</code>```

Online Demo

Title: Matlab unique cell combinations

Body:
I have a list as given below:

A= {[1 2], [2 1], [2 1 3],[3 4],[4 3]}

I need to simplify the matrix. For example, [3 4] and [4 3] form the same combination, only one of them is enough. Also, [1 2] and [2 1] is the same combinations, so I should be left with

newA= {[1 2],[2 1 3],[3 4]}

How do I do that?

Body:
Here is a solution using accumarray:

n = cellfun(@numel,A);
C=accumarray(n(:),1:numel(A),[],@(x){num2cell(unique(sort(vertcat(A{x}),2),'rows'),2)});
result = vertcat(C{~cellfun(@isempty,C)})

I tested 3 proposed answers with the following data in Octave:

A=arrayfun(@(x){randi([1 10],1,randi([1 10000]))},1:50);

Here is the result:

======NUM2STR=======:
Elapsed time is 1.13129 seconds.
======FOR LOOP=======:
Elapsed time is 0.237398 seconds.
======ACCUMARRAY=======:
Elapsed time is 0.036804 seconds.

With the following data:

A=arrayfun(@(x){randi([1 3],1,randi([1 5]))},1:500);

Result:

======NUM2STR=======:
Elapsed time is 0.384026 seconds.
======FOR LOOP=======:
Elapsed time is 10.9931 seconds.
======ACCUMARRAY=======:
Elapsed time is 0.0271118 seconds.

Online Demo


问:
Using ThreadPoolExecutor without Blocking
As a follow up on this question, I have a trivial script which starts a threadpoolexecutor to read in a json file. While doing that I want to it count from 1 to 9 using a for loop. For some reason even though I used executor.shutdown(wait=False) it still blocks and waits for the read_employees method to execute.

According to the documentation:

If wait is False then this method will return immediately and the resources associated with the executor will be freed when all pending futures are done executing

```<code>import concurrent.futures
import json
import time

def read_employees(read_file):
    with open(read_file) as f_obj:
        employees = json.load(f_obj)

    for emp in employees:
        print(emp)
        time.sleep(3)

def start_thread():
    filename = 'employee.json'
    with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
        executor.submit(read_employees, filename)
        executor.shutdown(wait=False)

def print_number():
    for num in range(1,10):
        time.sleep(2)
        print(num)

start_thread()
print_number()
</code>```

If I were to do this:

```<code>def read_employees(read_file):
    with open(read_file) as f_obj:
        employees = json.load(f_obj)

    for emp in employees:
        time.sleep(5)
        print(emp)

def print_number():
    for num in range(1,10):
        print(num)

filename = 'employee.json'
empThread = threading.Thread(target=read_employees, args=(filename,))
empThread.start()

print_number()
</code>```

It counts from 1 to 9 first and then prints out the employees, the delay is because of sleep while reading the employees. Like so:

```<code>1
2
3
4
5
6
7
8
9
ams@yourcompanyname.com
bcs@yourcompanyname.com
</code>```

How do I achieve the same output using the threadpoolexecutor without blocking?

答:
Probably due to this little snippet:

"You can avoid having to call this method explicitly if you use the with statement, which will shutdown the Executor (waiting as if Executor.shutdown() were called with wait set to True)"

https://docs.python.org/3/library/concurrent.futures.html

Body:
As a follow up on this question, I have a trivial script which starts a threadpoolexecutor to read in a json file. While doing that I want to it count from 1 to 9 using a for loop. For some reason even though I used executor.shutdown(wait=False) it still blocks and waits for the read_employees method to execute.

According to the documentation:

If wait is False then this method will return immediately and the resources associated with the executor will be freed when all pending futures are done executing

import concurrent.futures
import json
import time

def read_employees(read_file):
    with open(read_file) as f_obj:
        employees = json.load(f_obj)

    for emp in employees:
        print(emp)
        time.sleep(3)

def start_thread():
    filename = 'employee.json'
    with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
        executor.submit(read_employees, filename)
        executor.shutdown(wait=False)

def print_number():
    for num in range(1,10):
        time.sleep(2)
        print(num)

start_thread()
print_number()

If I were to do this:

def read_employees(read_file):
    with open(read_file) as f_obj:
        employees = json.load(f_obj)

    for emp in employees:
        time.sleep(5)
        print(emp)

def print_number():
    for num in range(1,10):
        print(num)

filename = 'employee.json'
empThread = threading.Thread(target=read_employees, args=(filename,))
empThread.start()

print_number()

It counts from 1 to 9 first and then prints out the employees, the delay is because of sleep while reading the employees. Like so:

1
2
3
4
5
6
7
8
9
ams@yourcompanyname.com
bcs@yourcompanyname.com

How do I achieve the same output using the threadpoolexecutor without blocking?


问:
How to search string in all files firefox developer 56
I can't find a way to search a string in all .js and .css files on Firefox Developer Edition 56.0b4.

I found a way, but it was before versions 52. I wonder why they removed this feature?

Thanks for help.

答:
While not listed on MDN Dev Tools Search page, Firefox Developer (Quantum) 58 once again includes the ability to search ALL files. I was missing this and almost defected to Chrome, but the tool set is way less intuitive.

From the debugger panel  Mac the key shortcut is CMD-SHIFT-F.


问:
Plotting lists in a Pandas dataframe
Consider the following dataframe example:

```<code>df = pd.DataFrame({'date':['12-01', '12-02', '12-03'],'list1': np.random.randint(0, 10, (3,5)).tolist(),
               'list2': np.random.randint(0, 10, (3,5)).tolist()},
               index=list('ABC'))
</code>```

I would like to plot the lists in the dataframe in such a way that I end up with 3 lines in my graph: A, B and C with for each one, 'list1' as x values and 'list2' as y values.

I started off by trying to plot the columns directly but the following returns an error:

```<code>In: df.iloc[0].plot(x='list1', y='list2')

Out: TypeError: Empty 'DataFrame': no numeric data to plot
</code>```

I could iterate over the rows of the dataframe and append the lists to a new list to plot them, but I feel that this defeats the purpose of storing my data in a dataframe (I have additional columns with ancillary data) and I am sure that there is a better way to do this.

I have about 20 entries in each dataframe (grouped from a larger dataframe) and the main purpose is to visually check if the values (output from an instrument) are in a certain range.

答:
Why not iterate the rows and plot the values?</p>

```<code>for i, row in df.iterrows():
    plt.plot(row['list1'], row['list2'])
</code>```

Title: Plotting lists in a Pandas dataframe

Body:
Consider the following dataframe example:

df = pd.DataFrame({'date':['12-01', '12-02', '12-03'],'list1': np.random.randint(0, 10, (3,5)).tolist(),
               'list2': np.random.randint(0, 10, (3,5)).tolist()},
               index=list('ABC'))

I would like to plot the lists in the dataframe in such a way that I end up with 3 lines in my graph: A, B and C with for each one, 'list1' as x values and 'list2' as y values.

I started off by trying to plot the columns directly but the following returns an error:

In: df.iloc[0].plot(x='list1', y='list2')

Out: TypeError: Empty 'DataFrame': no numeric data to plot

I could iterate over the rows of the dataframe and append the lists to a new list to plot them, but I feel that this defeats the purpose of storing my data in a dataframe (I have additional columns with ancillary data) and I am sure that there is a better way to do this.

I have about 20 entries in each dataframe (grouped from a larger dataframe) and the main purpose is to visually check if the values (output from an instrument) are in a certain range.

Body:
Why not iterate the rows and plot the values?

for i, row in df.iterrows():
    plt.plot(row['list1'], row['list2'])