问:
Making Python loggers log all stdout and stderr messages
Using the python logging package, and writing a class Log, I'd like to tee stdout and stderr to a log file :

```<code>log = Log("log.txt")
print "line1"
print "line2"
print >>sys.stderr, "err1"
del log
print "line to screen only"
</code>```

The output log file would contain :

```<code>16/11/2017 09:51:58 INFO - line1
16/11/2017 09:51:58 INFO - line2
16/11/2017 09:51:58 INFO - err1
</code>```

Any idea how to write this Log class, keeping the advantages of the "logging" package (time-stamps, ...) ?

答:
The right way to achieve what you ask is to use Logger object. It gives you much more flexability. This object can be bound to multiple handlers; You need a streamhandler to log message to sys.stdout and a file handler to log it to a file. You then both print to the screen and log to a file in a single command.

```<code>import logging

# create logger
logger = logging.getLogger('example')
logger.setLevel(logging.INFO)

# create file handler which logs messages
fh = logging.FileHandler('fh.log')
fh.setLevel(logging.DEBUG)

# create console handler to print to screen
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)

# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)

# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)
</code>```

Now every call to logger.info(msg) will be printed both to the screen, and written to fh.log file.

There is another way, where you can replace sys.stdout and sys.stderr stream objects. Create a class and customize it (original answer here):

```<code>import sys

class writer(object):
    _fh = None
    _orig_stdout = sys.stdout

   def __init__(self):
       _fh = open('logging.log', 'w')

    def write(self, data):
        fp.write(data)
        _orig_stdout.write(data)

    def flush():
        _orig_stdout.flush()

logger = writer()

sys.stdout = logger
sys.stderr = logger
</code>```

Body:
Using the python logging package, and writing a class Log, I'd like to tee stdout and stderr to a log file :

log = Log("log.txt")
print "line1"
print "line2"
print >>sys.stderr, "err1"
del log
print "line to screen only"

The output log file would contain :

16/11/2017 09:51:58 INFO - line1
16/11/2017 09:51:58 INFO - line2
16/11/2017 09:51:58 INFO - err1

Any idea how to write this Log class, keeping the advantages of the "logging" package (time-stamps, ...) ?

Body:
The right way to achieve what you ask is to use Logger object. It gives you much more flexability. This object can be bound to multiple handlers; You need a streamhandler to log message to sys.stdout and a file handler to log it to a file. You then both print to the screen and log to a file in a single command.

import logging

# create logger
logger = logging.getLogger('example')
logger.setLevel(logging.INFO)

# create file handler which logs messages
fh = logging.FileHandler('fh.log')
fh.setLevel(logging.DEBUG)

# create console handler to print to screen
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)

# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)

# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)

Now every call to logger.info(msg) will be printed both to the screen, and written to fh.log file.

There is another way, where you can replace sys.stdout and sys.stderr stream objects. Create a class and customize it (original answer here):

import sys

class writer(object):
    _fh = None
    _orig_stdout = sys.stdout

   def __init__(self):
       _fh = open('logging.log', 'w')

    def write(self, data):
        fp.write(data)
        _orig_stdout.write(data)

    def flush():
        _orig_stdout.flush()

logger = writer()

sys.stdout = logger
sys.stderr = logger


来源: stackexchange

问:
DrawableBottom Error in Android Sdk 17
I have a Button in my activity's layout like this:

```<code><Button
        android:id="@+id/button_before"
        android:layout_width="45dp"
        android:layout_height="25dp"
        android:layout_gravity="center_vertical|start"
        android:background="@color/transparent"
        android:drawableBottom="@drawable/ic_navigate_before"
        android:textColor="@color/gray_2" />
</code>```

It is ok when I run my app to a device with Android SDK >19 but when I run my app to a device with Android SDK <19 like 17, my activity unfortunately stopped and this error occurs:

```<code>11-16 08:57:41.042 3549-3549/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.app/com.myapp.app.SearchActivity}: android.view.InflateException: Binary XML file line #45: Error inflating class Button
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class Button
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                 at com.myapp.app.SearchActivity.onCreate(SearchActivity.java:90)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_navigate_before.xml from drawable resource ID #0x7f02007d
                                                 at android.content.res.Resources.loadDrawable(Resources.java:1958)
                                                 at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
                                                 at android.widget.TextView.<init>(TextView.java:769)
                                                 at android.widget.Button.<init>(Button.java:107)
                                                 at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
                                                 at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:62)
                                                 at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                 at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                 at com.myapp.app.SearchActivity.onCreate(SearchActivity.java:90)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
                                                 at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
                                                 at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
                                                 at android.content.res.Resources.loadDrawable(Resources.java:1955)
                                                 at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
                                                 at android.widget.TextView.<init>(TextView.java:769)
                                                 at android.widget.Button.<init>(Button.java:107)
                                                 at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
                                                 at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:62)
                                                 at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                 at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                 at com.myapp.app.SearchActivity.onCreate(SearchActivity.java:90)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
</code>```

When I remove this line from my layout XML activity runs ok in every device:

android:drawableBottom="@drawable/ic_navigate_before"

And ic_navigate_before is an XML file:

```<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="@color/gray_2"
    android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>
</vector>
</code>```

Also, my app min SDK is 16.
What can I do to resolve this problem?

答:
Hi refer this document for why the crash was occuring.

As it stated that 'You’ll find directly referencing vector drawables outside of app:srcCompat will fail prior to Lollipop.'

As I Know,
We cant directly set vector drawable.
From 23.3.0 version vector drawables can only be loaded via app:srcCompat or setImageResource()

Try below solution,
create new file drawable_navigate_before.xml file write down below code.

```<code> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:drawable="@drawable/ic_navigate_before"/>
 </layer-list>
</code>```

and now set this file as drawable in you layout file.

```<code>     android:drawableBottom="@drawable/drawable_navigate_before"
</code>```

ContentLicense: CC BY-SA 3.0

Title: DrawableBottom Error in Android Sdk 17

Body:
I have a Button in my activity's layout like this:

<Button
        android:id="@+id/button_before"
        android:layout_width="45dp"
        android:layout_height="25dp"
        android:layout_gravity="center_vertical|start"
        android:background="@color/transparent"
        android:drawableBottom="@drawable/ic_navigate_before"
        android:textColor="@color/gray_2" />

It is ok when I run my app to a device with Android SDK >19 but when I run my app to a device with Android SDK <19 like 17, my activity unfortunately stopped and this error occurs:

11-16 08:57:41.042 3549-3549/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.app/com.myapp.app.SearchActivity}: android.view.InflateException: Binary XML file line #45: Error inflating class Button
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class Button
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                 at com.myapp.app.SearchActivity.onCreate(SearchActivity.java:90)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_navigate_before.xml from drawable resource ID #0x7f02007d
                                                 at android.content.res.Resources.loadDrawable(Resources.java:1958)
                                                 at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
                                                 at android.widget.TextView.<init>(TextView.java:769)
                                                 at android.widget.Button.<init>(Button.java:107)
                                                 at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
                                                 at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:62)
                                                 at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                 at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                 at com.myapp.app.SearchActivity.onCreate(SearchActivity.java:90)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
                                                 at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
                                                 at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
                                                 at android.content.res.Resources.loadDrawable(Resources.java:1955)
                                                 at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
                                                 at android.widget.TextView.<init>(TextView.java:769)
                                                 at android.widget.Button.<init>(Button.java:107)
                                                 at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
                                                 at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:62)
                                                 at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                 at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                 at com.myapp.app.SearchActivity.onCreate(SearchActivity.java:90)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)

When I remove this line from my layout XML activity runs ok in every device:

android:drawableBottom="@drawable/ic_navigate_before"

And ic_navigate_before is an XML file:

<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="@color/gray_2"
    android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z"/>
</vector>

Also, my app min SDK is 16.
What can I do to resolve this problem?

Body:
Hi refer this document for why the crash was occuring.

As it stated that 'You’ll find directly referencing vector drawables outside of app:srcCompat will fail prior to Lollipop.'

As I Know,
We cant directly set vector drawable.
From 23.3.0 version vector drawables can only be loaded via app:srcCompat or setImageResource()

Try below solution,
create new file drawable_navigate_before.xml file write down below code.

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:drawable="@drawable/ic_navigate_before"/>
 </layer-list>

and now set this file as drawable in you layout file.

     android:drawableBottom="@drawable/drawable_navigate_before"


问:
Parse string with Python and pull numbers for simple math
I am running "Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2" on Ubuntu.

I have a line as follows from serial:

```<code>line="[99]  nodeId=99    uptime=31987895     BarC=1.15     sensorVal=226 -"
</code>```

and wish to parse this. I need to extract 1.15 and 226 as numbers so I can do math with those numbers.

I have used the following python code:

```<code>pressure=line.split()[3].split("=")[1:2]
print(pressure)
</code>```

This prints this:

```<code>['1.15']
</code>```

How do I get rid of the  ' ' (apostrophes) and the  [  ]  and turn this into something I can do simple math with. A floating number will be fine.

Here is more output:

```<code>Listening at 868 Mhz...
[99]  nodeId=99    uptime=48743987     BarC=1.19     sensorVal=229 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48745052     BarC=1.19     sensorVal=229
[99]  nodeId=99    uptime=48527151     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48528216     BarC=1.20     sensorVal=230
[99]  nodeId=99    uptime=48529276     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48530341     BarC=1.20     sensorVal=230
[99]  nodeId=99    uptime=48531402     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48532467     BarC=1.20     sensorVal=230
[99]  nodeId=99    uptime=48533528     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48534594     BarC=1.20     sensorVal=230
[99]  nodeId=99    uptime=48535655     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48536720     BarC=1.20     sen**
</code>```

答:
Here are two non-regex solutions.

The first simply uses the (apparent) fact that the data is presented using fixed width fields. In each data line the value for BarC starts at offset 44 and ends before position 53. Similarly sensorVal starts at offset 63 and ends before 67. You can use string slicing to extract the values like this:

```<code>line = "[99]  nodeId=99    uptime=31987895     BarC=1.15     sensorVal=226 -"

if `BarC` in line:        # test whether this is a data line
    pressure = float(line[44:53])
    sensor_val = int(line[63:67])
</code>```

Another way is to use split() to break the line up, then look for substrings containing an =. Then split the substrings into key/value pairs and create a dictionary:

```<code>data = {}
if 'BarC' in line:
    for s in line.split():
        if '=' in s:
            key, value = s.split('=')
            data[key] = value

print(data)
# {'BarC': '1.15', 'uptime': '31987895', 'nodeId': '99', 'sensorVal': '226'}
</code>```

This can be reduced to this one-liner:

```<code>data = dict([s.split('=') for s in line.split() if 'BarC' in line and '=' in s])
print(data)
# {'BarC': '1.15', 'uptime': '31987895', 'nodeId': '99', 'sensorVal': '226'}
</code>```

You can convert the values into the required data type using float() or int() as required:

```<code>>>> float(data['BarC'])
1.15
</code>```

Body:
I am running "Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2" on Ubuntu.

I have a line as follows from serial:

line="[99]  nodeId=99    uptime=31987895     BarC=1.15     sensorVal=226 -"

and wish to parse this. I need to extract 1.15 and 226 as numbers so I can do math with those numbers.

I have used the following python code:

pressure=line.split()[3].split("=")[1:2]
print(pressure)

This prints this:

['1.15']

How do I get rid of the  ' ' (apostrophes) and the  [  ]  and turn this into something I can do simple math with. A floating number will be fine.

Here is more output:

Listening at 868 Mhz...
[99]  nodeId=99    uptime=48743987     BarC=1.19     sensorVal=229 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48745052     BarC=1.19     sensorVal=229
[99]  nodeId=99    uptime=48527151     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48528216     BarC=1.20     sensorVal=230
[99]  nodeId=99    uptime=48529276     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48530341     BarC=1.20     sensorVal=230
[99]  nodeId=99    uptime=48531402     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48532467     BarC=1.20     sensorVal=230
[99]  nodeId=99    uptime=48533528     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48534594     BarC=1.20     sensorVal=230
[99]  nodeId=99    uptime=48535655     BarC=1.20     sensorVal=230 - ACK sent. Sending packet to node 99 - waiting for ACK...nothing...
[99]  nodeId=99    uptime=48536720     BarC=1.20     sen**

Body:
Here are two non-regex solutions.

The first simply uses the (apparent) fact that the data is presented using fixed width fields. In each data line the value for BarC starts at offset 44 and ends before position 53. Similarly sensorVal starts at offset 63 and ends before 67. You can use string slicing to extract the values like this:

line = "[99]  nodeId=99    uptime=31987895     BarC=1.15     sensorVal=226 -"

if `BarC` in line:        # test whether this is a data line
    pressure = float(line[44:53])
    sensor_val = int(line[63:67])

Another way is to use split() to break the line up, then look for substrings containing an =. Then split the substrings into key/value pairs and create a dictionary:

data = {}
if 'BarC' in line:
    for s in line.split():
        if '=' in s:
            key, value = s.split('=')
            data[key] = value

print(data)
# {'BarC': '1.15', 'uptime': '31987895', 'nodeId': '99', 'sensorVal': '226'}

This can be reduced to this one-liner:

data = dict([s.split('=') for s in line.split() if 'BarC' in line and '=' in s])
print(data)
# {'BarC': '1.15', 'uptime': '31987895', 'nodeId': '99', 'sensorVal': '226'}

You can convert the values into the required data type using float() or int() as required:

>>> float(data['BarC'])
1.15


问:
How to stop tomcat through a Java program?
I am starting the embedded tomcat successfully through Java program. But I am unable to stop the tomcat server. How do I stop tomcat through a Java program?.</p>

答:
How about a System.exec ("tomcatInstallPath/bin/shutdown.sh")

Just a sugestion, I've never tried it.
I just like quick/fast/direct solutions.

ContentLicense: CC BY-SA 2.5


问:
Getting evaluate data and cookies of data from nightmare request
How can I make one request to get document.title and the cookies in one nightmare request?

```<code>const Nightmare = require('nightmare')

Nightmare()
    .goto('http://cnn.com')
    .evaluate(() => document.title)
    .end()
    .then(console.log)

Nightmare()
    .goto('http://cnn.com')
    .cookies.get()
    .end()
    .then(console.log)
</code>```

答:
This works:</p>

```<code>const Nightmare = require('nightmare')
const nightmare = Nightmare()

async function example () {
    const call = nightmare
        .goto('http://cnn.com')

    const title = await call
        .evaluate(() => document.title)

    const cookies = await call
        .cookies.get()

    await call.end()
    return {title, cookies}
}
</code>```

Body:
How can I make one request to get document.title and the cookies in one nightmare request?

const Nightmare = require('nightmare')

Nightmare()
    .goto('http://cnn.com')
    .evaluate(() => document.title)
    .end()
    .then(console.log)

Nightmare()
    .goto('http://cnn.com')
    .cookies.get()
    .end()
    .then(console.log)

Body:
This works:

const Nightmare = require('nightmare')
const nightmare = Nightmare()

async function example () {
    const call = nightmare
        .goto('http://cnn.com')

    const title = await call
        .evaluate(() => document.title)

    const cookies = await call
        .cookies.get()

    await call.end()
    return {title, cookies}
}


问:
How to filter a sequence and retain evaluated pred values?
This is a scenario I encountered many times, yet didn't find an idiomatic approach for it...

Suppose one would like to use a self-defined self-pred function to filter a seq. This self-pred function returns nil for unwanted elements, and useful information for wanted elements. It is desirable to keep the evaluated self-pred values for these wanted elements.

My general solution is:

```<code>;; self-pred is a pred function which returns valuable info
;; in general, they are unique and can be used as key
(let [new-seq (filter self-pred aseq)]
   (zipmap (map self-pred new-seq) new-seq))
</code>```

Basically, it is to call self-pred twice on all wanted elements. I feel it is so ugly...

Wonder if there is any better ways. Much appreciated for any input!

答:
In these scenarios you can use keep, but you have to change your "predicate" function to return the full information you need, or nil, for each item.

For example:

```<code>(keep (fn [item]
         (when-let [tested (some-test item)]
           (assoc item :test-output tested))) aseq)
</code>```

Body:
This is a scenario I encountered many times, yet didn't find an idiomatic approach for it...

Suppose one would like to use a self-defined self-pred function to filter a seq. This self-pred function returns nil for unwanted elements, and useful information for wanted elements. It is desirable to keep the evaluated self-pred values for these wanted elements.

My general solution is:

;; self-pred is a pred function which returns valuable info
;; in general, they are unique and can be used as key
(let [new-seq (filter self-pred aseq)]
   (zipmap (map self-pred new-seq) new-seq))

Basically, it is to call self-pred twice on all wanted elements. I feel it is so ugly...

Wonder if there is any better ways. Much appreciated for any input!

Body:
In these scenarios you can use keep, but you have to change your "predicate" function to return the full information you need, or nil, for each item.

For example:

(keep (fn [item]
         (when-let [tested (some-test item)]
           (assoc item :test-output tested))) aseq)


问:
MySQL Like statement in SELECT column_name
I am trying to select the column names from a specific table, where the table name is like '98673'

So I am using this:

```<code>SELECT
    column_name
FROM
    information_schema.columns
WHERE
    table_name='lime_survey_98673'
    AND column_name LIKE '98673'
</code>```

However this will not result in any data.
Though I do have column names with '98673Blah' in there.

I know I must be doing something wrong, but what??

答:
One can do it this way too :

```<code>show columns from lime_survey_98673 like '%98673%';
</code>```

Body:
I am trying to select the column names from a specific table, where the table name is like '98673'

So I am using this:

SELECT
    column_name
FROM
    information_schema.columns
WHERE
    table_name='lime_survey_98673'
    AND column_name LIKE '98673'

However this will not result in any data.
Though I do have column names with '98673Blah' in there.

I know I must be doing something wrong, but what??

Body:
One can do it this way too :

show columns from lime_survey_98673 like '%98673%';


问:
Listbox with checkbox not triggering selected item when checkbox is checked/unchecked
My application is developed using wpf MVVM pattern where i have a list box which shows a set of operations to be selected with checkbox to check/uncheck. I need to get the selected item whenever a checkbox is checked / unchecked. I am binding the IsChecked property of checkbox to property in my model and selecteditem property of listbox to property in my viewmodel. Whenever i check/uncheck the frist item in the list the selected item event is triggering however the same is not getting triggered when i check/uncheck any item other than the first selected item in the list. I need to capture the changes whenever the user does any changes to listbox items.
Here is my view:

```<code><ListBox Height="280" Width="Auto" ItemsSource="{Binding OperationsInfoCol}" SelectionMode="Multiple"
                        SelectedItem="{Binding Path=SelectedOperationItem,UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding CanEnableListBox}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox  Content="{Binding OperationName}"
                                              IsChecked="{Binding Path=IsOperationSelected,Mode=TwoWay}" IsEnabled="{Binding Path=CanEnableOperation,Mode=TwoWay}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="IsSelected" Value="{Binding IsOperationSelected,Mode=TwoWay}"/>
            <Setter Property="IsEnabled" Value="{Binding CanEnableOperation,Mode=TwoWay}"/>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="Red"/>
                </Trigger>
            </Style.Triggers>

        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
</code>```

ViewModel:

```<code>   public OperationsInfo SelectedOperationItem
    {
        get
        {
            return m_oOperationSelected;
        }
        set
        {
            if (value != null)
            {
                m_oOperationSelected = value;
                OnPropertyChanged("SelectedOperationItem");
                if (null != m_oOperationSelected)
                {
                    ObservableCollection<OperationsInfo> oCol = new ObservableCollection<OperationsInfo>();
                    //if (m_oOperationSelected.CanEnableOperation)
                    {
                        foreach (OperationsInfo itm in OperationsInfoCol)
                        {
                            if (itm.OperationId == m_oOperationSelected.OperationId && m_oOperationSelected.CanEnableOperation)
                            {
                                itm.IsOperationSelected = !m_oOperationSelected.IsOperationSelected;
                            }
                            oCol.Add(itm);
                        }

                        OperationsInfoCol.Clear();
                        OperationsInfoCol = oCol;
                    }
                }
            }
        }
    }
</code>```

Model:

```<code>public class OperationsInfo    {

    private string m_strOperationName;
    private int m_nOperationId;
    private bool m_bIsOperationSelected;
    private bool m_bCanEnable;
    private LicenseManagerViewModel m_VMLicenseManager;

public bool IsOperationSelected
    {
        get
        {
            return m_bIsOperationSelected;
        }
        set
        {
            m_bIsOperationSelected = value;
            LicenseManagerVM.OperationInfoChecked = value;
        }
    }

}
</code>```

答:
You should probably bind IsChecked to the IsSelected property of the container ListBoxItem

That way you can handle the SelectionChanged event of the ListBox and react to any changes. (use e.AddedItems and e.RemovedItems to find out what changes where made.)

Some code example:

```<code>     <ListBox ItemsSource="{Binding Data}" SelectionChanged="ListBox_SelectionChanged" SelectionMode="Extended">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <CheckBox Content="{Binding Name}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</code>```

Behind:

```<code>    private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
    {
        ListBox lb = sender as ListBox;
        if (e.AddedItems.Count > 0)
        {
            foreach (Employee emp in e.AddedItems.Cast<Employee>()) MessageBox.Show("Added: " + emp.Name);
        }
        if (e.RemovedItems.Count > 0)
        {
            foreach (Employee emp in e.RemovedItems.Cast<Employee>()) MessageBox.Show("Removed: " + emp.Name);
        }
    }
</code>```

Body:
My application is developed using wpf MVVM pattern where i have a list box which shows a set of operations to be selected with checkbox to check/uncheck. I need to get the selected item whenever a checkbox is checked / unchecked. I am binding the IsChecked property of checkbox to property in my model and selecteditem property of listbox to property in my viewmodel. Whenever i check/uncheck the frist item in the list the selected item event is triggering however the same is not getting triggered when i check/uncheck any item other than the first selected item in the list. I need to capture the changes whenever the user does any changes to listbox items.
Here is my view:

<ListBox Height="280" Width="Auto" ItemsSource="{Binding OperationsInfoCol}" SelectionMode="Multiple"
                        SelectedItem="{Binding Path=SelectedOperationItem,UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding CanEnableListBox}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox  Content="{Binding OperationName}"
                                              IsChecked="{Binding Path=IsOperationSelected,Mode=TwoWay}" IsEnabled="{Binding Path=CanEnableOperation,Mode=TwoWay}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemContainerStyle>

        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

ViewModel:

   public OperationsInfo SelectedOperationItem
    {
        get
        {
            return m_oOperationSelected;
        }
        set
        {
            if (value != null)
            {
                m_oOperationSelected = value;
                OnPropertyChanged("SelectedOperationItem");
                if (null != m_oOperationSelected)
                {
                    ObservableCollection<OperationsInfo> oCol = new ObservableCollection<OperationsInfo>();
                    //if (m_oOperationSelected.CanEnableOperation)
                    {
                        foreach (OperationsInfo itm in OperationsInfoCol)
                        {
                            if (itm.OperationId == m_oOperationSelected.OperationId && m_oOperationSelected.CanEnableOperation)
                            {
                                itm.IsOperationSelected = !m_oOperationSelected.IsOperationSelected;
                            }
                            oCol.Add(itm);
                        }

                        OperationsInfoCol.Clear();
                        OperationsInfoCol = oCol;
                    }
                }
            }
        }
    }

Model:

public class OperationsInfo    {

    private string m_strOperationName;
    private int m_nOperationId;
    private bool m_bIsOperationSelected;
    private bool m_bCanEnable;
    private LicenseManagerViewModel m_VMLicenseManager;

public bool IsOperationSelected
    {
        get
        {
            return m_bIsOperationSelected;
        }
        set
        {
            m_bIsOperationSelected = value;
            LicenseManagerVM.OperationInfoChecked = value;
        }
    }

}

Body:
You should probably bind IsChecked to the IsSelected property of the container ListBoxItem

That way you can handle the SelectionChanged event of the ListBox and react to any changes. (use e.AddedItems and e.RemovedItems to find out what changes where made.)

Some code example:

     <ListBox ItemsSource="{Binding Data}" SelectionChanged="ListBox_SelectionChanged" SelectionMode="Extended">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <CheckBox Content="{Binding Name}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

Behind:

    private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
    {
        ListBox lb = sender as ListBox;
        if (e.AddedItems.Count > 0)
        {
            foreach (Employee emp in e.AddedItems.Cast<Employee>()) MessageBox.Show("Added: " + emp.Name);
        }
        if (e.RemovedItems.Count > 0)
        {
            foreach (Employee emp in e.RemovedItems.Cast<Employee>()) MessageBox.Show("Removed: " + emp.Name);
        }
    }


问:
How to append the output from ProcessBuilder to file,without overwriting the exisiting data in file
While trying to append the Output from ProcessBuilder to file using
redirectOutput(Redirect.appendTo(outFile).file()), it always overwrites the existing data in the file , instead of appending the data to the existing file.

How to append data to an existing file from processbuilder

Any help would be appreciated.

答:
```<code>redirectOutput(Redirect.appendTo(outFile).file())
</code>```

You're losing the append information. This should be:

```<code>redirectOutput(Redirect.appendTo(outFile))
</code>```

Body:
redirectOutput(Redirect.appendTo(outFile).file())

You're losing the append information. This should be:

redirectOutput(Redirect.appendTo(outFile))


问:
Nested paralleled regions OpenMP
What does it mean in OpenMP that

Nested parallel regions are serialized by default

Does it mean threads do it continuously? I also can not underestend this part:

```<code>A throw executed inside a parallel region must cause execution to resume within
the dynamic extent of the same structured block, and it must be caught by the
same thread that threw the exception.
</code>```

答:
As explained here (scroll down to "17.1 Nested parallelism", by default a nested parallel region will not be parallelized, thus run sequentially. Nested thread creation is possible using either OMP_NESTED=true (as environment variable) or omp_set_nested(1) (in your code).

EDIT: also see this answer to a similar question.

Title: Nested paralleled regions OpenMP

Body:
What does it mean in OpenMP that

Nested parallel regions are serialized by default

Does it mean threads do it continuously? I also can not underestend this part:

A throw executed inside a parallel region must cause execution to resume within
the dynamic extent of the same structured block, and it must be caught by the
same thread that threw the exception.


问:
if conditionals (maybe) Giving a user 3 out of 12 chance when selecting buttons
I'm a complete novice when it comes to HTML5 actions and I'd really like some help trying to figure out a very specific issue if you would?

I have 12 squares (buttons), each button pulls a single random answer from a pot of 12. Each time a single button is selected and the answer is shown the button disappears. So far I have all this working.

The next step is that I want the user to only be able to choose 3 of the 12 buttons - any three, entirely at random and when the 3 have been selected the rest become inactive.

Any help you can provide would really help me,

(by the way I work through Adobe Animate CC)

Thanks,

Aidan

答:
After third button is clicked; every other button disables;

let buttons = document.getElementsByClassName("activeButton")
let noOfButtonsClicked = 0;
for (i = 0; i < buttons.length; i++) {
  buttons[i].onclick = function(e) {
    noOfButtonsClicked += 1;
    document.getElementById("chosenRandomNumber").innerHTML = Math.floor(Math.random() * (20));
    e.path[0].classList += " clickedButton"
    if (noOfButtonsClicked == 3) {
      disableButtons();
    }
  }
}

function disableButtons() {
  for (i = 0; i < buttons.length; i++) {

    if (!buttons[i].classList.contains('clickedButton')) {
      buttons[i].setAttribute('disabled', true);
    }
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><button class="activeButton">Button 1</button>
<button class="activeButton">Button 2</button>
<button class="activeButton">Button 3</button>
<button class="activeButton">Button 4</button>
<button class="activeButton">Button 5</button>
<button class="activeButton">Button 6</button>
<button class="activeButton">Button 7</button>
<button class="activeButton">Button 8</button>
<button class="activeButton">Button 9</button>
<button class="activeButton">Button 10</button>
<button class="activeButton">Button 11</button>
<button class="activeButton">Button 12</button>

<div id="chosenRandomNumber">
</div></code>```

Body:
After third button is clicked; every other button disables;

let buttons = document.getElementsByClassName("activeButton")
let noOfButtonsClicked = 0;
for (i = 0; i < buttons.length; i++) {
  buttons[i].onclick = function(e) {
    noOfButtonsClicked += 1;
    document.getElementById("chosenRandomNumber").innerHTML = Math.floor(Math.random() * (20));
    e.path[0].classList += " clickedButton"
    if (noOfButtonsClicked == 3) {
      disableButtons();
    }
  }
}

function disableButtons() {
  for (i = 0; i < buttons.length; i++) {

    if (!buttons[i].classList.contains('clickedButton')) {
      buttons[i].setAttribute('disabled', true);
    }
  }
}

<button class="activeButton">Button 1</button>
<button class="activeButton">Button 2</button>
<button class="activeButton">Button 3</button>
<button class="activeButton">Button 4</button>
<button class="activeButton">Button 5</button>
<button class="activeButton">Button 6</button>
<button class="activeButton">Button 7</button>
<button class="activeButton">Button 8</button>
<button class="activeButton">Button 9</button>
<button class="activeButton">Button 10</button>
<button class="activeButton">Button 11</button>
<button class="activeButton">Button 12</button>

<div id="chosenRandomNumber">
</div>


问:
How to get the particular div values using jQuery
Here I have one row, in that one row I have three div, my requirement is suppose if I am click the free plan button means I want to take only the that particular div values like Plan Name: Free Plan and Bonus Contact details up to : 00, I tried but I am not able to take the exact values if anyone know means please update my answer.Please see below I have posted my code what I tried, I spent too much to this but still I am not getting my answer.

```<code><section id="pricing-table">
  <div class="row pricelistNew">
    <div class="pricing">
      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Easy Plan </p>
            <p class="pricing-rate">₹ 1000 <br><span>Including All Tax</span></p>
            <a class="btn btn-custom payNow">Easy Plan</a>
          </div>

          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 25</li>
              <li>Bonus Contact details up to : 2</li>
              <li>Area Master Assistance : No</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>

      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Cool Plan </p>
            <p class="pricing-rate">₹ 2000 <br><span>Including All Tax</span></p>
            <a class="btn btn-custom payNow">Cool Plan</a>
          </div>

          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 48</li>
              <li>Bonus Contact details up to : 4</li>
              <li>Area Master Assistance : Yes</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>

      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Free Plan </p>
            <p class="pricing-rate">₹ 0 <br><span>Including All Tax</span></p>
            <a class="btn btn-custom payNow">Free Plan</a>
          </div>

          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 5</li>
              <li>Bonus Contact details up to : 00</li>
              <li>Area Master Assistance : No</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
</code>```

My jQuery code

```<code>$(function() {
  $(".payNow").on("click", function(e) {
    var $list = $(this).closest(".pricelistNew");
    name = $list.find(".myTitle").text();
    console.log(name);
  });
});
</code>```

Here I am getting all title names like

Easy Plan Cool Plan Free Plan

答:
Try this.

$(function() {
  $(".payNow").on("click", function(e) {
    var list = $(this).closest(".pricing-header");
    var name = list.find(".myTitle").text();
    console.log(name);
  });
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id="pricing-table">
  <div class="row pricelistNew">
    <div class="pricing">
      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Easy Plan </p>
            <p class="pricing-rate">₹ 1000
              <br><span>Including All Tax</span>
            </p>
            Easy Plan
          </div>
          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 25</li>
              <li>Bonus Contact details up to : 2</li>
              <li>Area Master Assistance : No</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>
      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Cool Plan </p>
            <p class="pricing-rate">₹ 2000
              <br><span>Including All Tax</span>
            </p>
            Cool Plan
          </div>
          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 48</li>
              <li>Bonus Contact details up to : 4</li>
              <li>Area Master Assistance : Yes</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>
      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Free Plan </p>
            <p class="pricing-rate">₹ 0
              <br><span>Including All Tax</span>
            </p>
            Free Plan
          </div>
          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 5</li>
              <li>Bonus Contact details up to : 00</li>
              <li>Area Master Assistance : No</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</section></code>```

Body:
Here I have one row, in that one row I have three div, my requirement is suppose if I am click the free plan button means I want to take only the that particular div values like Plan Name: Free Plan and Bonus Contact details up to : 00, I tried but I am not able to take the exact values if anyone know means please update my answer.Please see below I have posted my code what I tried, I spent too much to this but still I am not getting my answer.

Easy Plan

₹ 1000
Including All Tax

            Easy Plan

Contacts details up to : 25

Bonus Contact details up to : 2

Area Master Assistance : No

Contact details through sms : Yes

Cool Plan

₹ 2000
Including All Tax

            Cool Plan

Contacts details up to : 48

Bonus Contact details up to : 4

Area Master Assistance : Yes

Contact details through sms : Yes

Free Plan

₹ 0
Including All Tax

            Free Plan

Contacts details up to : 5

Bonus Contact details up to : 00

Area Master Assistance : No

Contact details through sms : Yes

My jQuery code

$(function() {
  $(".payNow").on("click", function(e) {
    var $list = $(this).closest(".pricelistNew");
    name = $list.find(".myTitle").text();
    console.log(name);
  });
});

Here I am getting all title names like

Easy Plan Cool Plan Free Plan

Body:
Try this.

$(function() {
  $(".payNow").on("click", function(e) {
    var list = $(this).closest(".pricing-header");
    var name = list.find(".myTitle").text();
    console.log(name);
  });
});

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id="pricing-table">
  <div class="row pricelistNew">
    <div class="pricing">
      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Easy Plan </p>
            <p class="pricing-rate">₹ 1000
              <br><span>Including All Tax</span>
            </p>
            <a class="btn btn-custom payNow">Easy Plan</a>
          </div>
          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 25</li>
              <li>Bonus Contact details up to : 2</li>
              <li>Area Master Assistance : No</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>
      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Cool Plan </p>
            <p class="pricing-rate">₹ 2000
              <br><span>Including All Tax</span>
            </p>
            <a class="btn btn-custom payNow">Cool Plan</a>
          </div>
          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 48</li>
              <li>Bonus Contact details up to : 4</li>
              <li>Area Master Assistance : Yes</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>
      <div class="col-md-4 col-sm-12 col-xs-12">
        <div class="pricing-table">
          <div class="pricing-header">
            <p class="pricing-title myTitle">Free Plan </p>
            <p class="pricing-rate">₹ 0
              <br><span>Including All Tax</span>
            </p>
            <a class="btn btn-custom payNow">Free Plan</a>
          </div>
          <div class="pricing-list">
            <ul>
              <li>Contacts details up to : 5</li>
              <li>Bonus Contact details up to : 00</li>
              <li>Area Master Assistance : No</li>
              <li>Contact details through sms : Yes</li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>


问:
how can i get bank account number from source in stripe API?
I am using ACH payment for collecting money from customer as investment. I can add bank account using plaid and stripe. But how can i get bank account number from source in stripe API?</p>

答: You cannot. By design, Stripe's API will not return the full account number, only the last 4 digits (via the last4 attribute).


问:
Are there any good oracle podcasts?
Are there any good oracle podcasts around? The only ones I've found is produced by oracle corp, and as such are little more than advertising pieces pushing their technology of the moment.

I'm specifically interested in Database technologies.

答: Here's a list: http://www.oracle.com/podcasts/index.html</p>

OwnerDisplayName: Matthew Watson

Title: Are there any good oracle podcasts?

LastEditorDisplayName: huseyint

OwnerDisplayName: Vaibhav


问:
iPhone: Splash screen in app - Good or Bad?
I'm going to submit a Lifestyle app to the App Store. I'm confused whether to add a Splash Screen to the App or not ?

Please advise me whether it's a good or bad idea as far as usability and App Store's submission guidelines are concerned.

答:
The developers guides mostly suggest a splash that looks like the starting screen of your app, to give people the impression the app has started. This has the bonus of allowing the user to start figuring out what they want to do while the program finishes loading.

From a users standpoint, I dislike most splash screens, I just want to get to the program, not look once again at what constitutes an advertisement for the program.


问:
Convert .NET Windows Service to Azure Web Job
I have a .NET Windows Service and would like to convert to Azure Web Jobs. Please let me know if I can host it as an Azure Web Jobs or a recommendation to convert.</p>

答: You could convert your service to a console application and run it as a continuous web job. Simply put a run.cmd inside the same directory that will start your .exe file (see Run Background tasks with WebJobs in Azure App Service).</p>


问:
Node Driver startup issue V1
I am running into an issue after upgrading a custom cordapp from M13 to V1. I have a small test suite which launches nodes using the node driver, and after upgrading to version 1 I get an issue which seems to be caused by the cordadevcakeys.jks file being null (see the error stack below). To upgrade I simply changed the build gradle release version and gradle plugins version from 0.13.0 to 1.0.0 - I am not sure if there is a step I am missing here that could potentially cause this error? I have also pulled the latests version 1 Corda project locally - although I was under the impression that this step isnt needed.

```<code>[ERROR] 12:45:26,017 [main] (Driver.kt:396) driver.DriverDSL.genericDriver -
Driver shutting down because of exception
java.lang.ExceptionInInitializerError: null
at net.corda.testing.driver.DriverDSL.start(Driver.kt:796) ~[corda-node-driver-1.0.0.jar:?]
at net.corda.testing.driver.Driver.genericDriver(Driver.kt:393) [corda-node-driver-1.0.0.jar:?]
at net.corda.testing.driver.Driver.driver(Driver.kt:317) [corda-node-driver-1.0.0.jar:?]
at net.corda.testing.driver.Driver.driver$default(Driver.kt:314) [corda-node-driver-1.0.0.jar:?]
at src.DeploymentTestKt.main(DeploymentTest.kt:29) [main/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65) [idea_rt.jar:?]
Caused by: java.lang.IllegalStateException: ClassLoader.getSystemRes…ates/cordadevcakeys.jks") must not be null
at net.corda.testing.TestConstants$DEV_CA$2.invoke(TestConstants.kt:72) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.TestConstants$DEV_CA$2.invoke(TestConstants.kt) ~[corda-test-utils-1.0.0.jar:?]
at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130) ~[kotlin-stdlib-1.1.4.jar:1.1.4]
at net.corda.testing.TestConstants.getDEV_CA(TestConstants.kt) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.CoreTestUtils.getTestPartyAndCertificate$default(CoreTestUtils.kt:145) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.CoreTestUtils.getBOC_IDENTITY(CoreTestUtils.kt:75) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.CoreTestUtils.getBOC(CoreTestUtils.kt:76) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.CoreTestUtils.<clinit>(CoreTestUtils.kt:77) ~[corda-test-utils-1.0.0.jar:?]
... 10 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.corda.testing.CoreTestUtils
at net.corda.testing.driver.ShutdownManager.shutdown(Driver.kt:505)
at net.corda.testing.driver.DriverDSL.shutdown(Driver.kt:627)
at net.corda.testing.driver.Driver.genericDriver(Driver.kt:399)
at net.corda.testing.driver.Driver.driver(Driver.kt:317)
at net.corda.testing.driver.Driver.driver$default(Driver.kt:314)
at src.DeploymentTestKt.main(DeploymentTest.kt:29)
... 5 more
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: Could not initialize class net.corda.testing.CoreTestUtils
at net.corda.testing.driver.ShutdownManager.shutdown(Driver.kt:505)
at net.corda.testing.driver.DriverDSL.shutdown(Driver.kt:627)
at net.corda.testing.driver.Driver$genericDriver$shutdownHook$1.invoke(Driver.kt:391)
at net.corda.testing.driver.Driver$genericDriver$shutdownHook$1.invoke(Driver.kt)
at net.corda.nodeapi.internal.ShutdownHookKt$addShutdownHook$hook$1.run(ShutdownHook.kt:15)
at java.lang.Thread.run(Thread.java:748)
</code>```

I can post the code I am using to launch the driver if need be, but by having a look at the cordapp-example it seems my method for starting the driver and nodes is correct, and it was working on M13.

*Edit, added in my gradle build and node driver code

```<code>apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'maven-publish'
apply plugin: 'application'
apply plugin: 'net.corda.plugins.quasar-utils'

repositories {
    mavenLocal()
    jcenter()
    mavenCentral()
    maven { url 'https://dl.bintray.com/kotlin/exposed' }
    maven { url 'https://jitpack.io' }
}

sourceSets {
    main {
        resources {
            srcDir "../config/dev"
        }
    }
    test {
        resources {
            srcDir "../config/test"
        }
    }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
    compileOnly "co.paralleluniverse:capsule:1.0.1"
    compile 'net.sourceforge.plantuml:plantuml:8039'

    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
    testCompile "junit:junit:$junit_version"

    //Corda integration dependencies
    cordaCompile "net.corda:corda-core:$corda_release_version"
    cordaCompile "net.corda:corda-finance:$corda_release_version"
    cordaCompile "net.corda:corda-jackson:$corda_release_version"
    cordaCompile "net.corda:corda-jfx:$corda_release_version"
    cordaCompile "net.corda:corda-rpc:$corda_release_version"
    cordaCompile "net.corda:corda-node-api:$corda_release_version"
    cordaCompile "net.corda:corda-webserver-impl:$corda_release_version"
    cordaCompile "net.corda:corda-test-utils:$corda_release_version"
    testCompile "net.corda:corda-test-utils:$corda_release_version"
    cordaRuntime "net.corda:corda:$corda_release_version"
    cordaRuntime "net.corda:corda-webserver:$corda_release_version"
    cordaCompile "net.corda:corda-node-driver:$corda_release_version"
    //testCompile "net.corda:corda-node-driver:$corda_release_version"
    cordapp "net.corda:corda-finance:$corda_release_version"

//    cordaCompile "net.corda:corda-core:$corda_release_version"
//    cordaCompile "net.corda:corda-finance:$corda_release_version"
//    cordaCompile "net.corda:corda-jackson:$corda_release_version"
//    cordaCompile "net.corda:corda-rpc:$corda_release_version"
//    cordaCompile "net.corda:corda-node-api:$corda_release_version"
//    cordaCompile "net.corda:corda-webserver-impl:$corda_release_version"
//    cordaRuntime "net.corda:corda:$corda_release_version"
//    cordaRuntime "net.corda:corda-webserver:$corda_release_version"
//    testCompile "net.corda:corda-test-utils:$corda_release_version"
//    cordaCompile "net.corda:corda-node-driver:$corda_release_version"
//    testCompile "net.corda:corda-node-driver:$corda_release_version"

}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        languageVersion = "1.1"
        apiVersion = "1.1"
        jvmTarget = "1.8"
        javaParameters = true   // Useful for reflection.
    }
}

task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
    directory "./build/nodes"
    networkMap "CN=Controller,O=R3,OU=corda,L=London,C=UK"
    node {
        name "CN=Controller,O=R3,OU=corda,L=London,C=UK"
        advertisedServices = ["corda.notary.validating"]
        p2pPort 10002
        rpcPort 10003
        cordapps = ["secLendModel"]
    }
    node {
        name "CN=NodeA,O=NodeA,L=London,C=UK"
        advertisedServices = []
        p2pPort 10005
        rpcPort 10006
        webPort 10007
        cordapps = ["secLendModel"]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": []]]
    }
    node {
        name "CN=NodeB,O=NodeB,L=New York,C=US"
        advertisedServices = []
        p2pPort 10008
        rpcPort 10009
        webPort 10010
        cordapps = ["secLendModel"]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": []]]
    }
    node {
        name "CN=NodeC,O=NodeC,L=Paris,C=FR"
        advertisedServices = []
        p2pPort 10011
        rpcPort 10012
        webPort 10013
        cordapps = ["secLendModel"]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": []]]
    }
}

// TODO: Make into gradle plugin without any references to Jython
task installJythonDeps(dependsOn: ['build']) {
    project.copy {
        from project.configurations.runtime
        into "build/jythonDeps"
    }
}

installJythonDeps.shouldRunAfter build

idea {
    module {
        downloadJavadoc = true // defaults to false
        downloadSources = true
    }
}

publishing {
    publications {
        jarAndSources(MavenPublication) {
            from components.java
            artifactId 'secLendModel'

            artifact sourceJar
            artifact javadocJar
        }
    }
}

task runTemplateClientRPC(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'com.template.client.TemplateClientRPCKt'
    args 'localhost:10006'
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
</code>```

and this is my node driver code

```<code>fun runSimulation() {
        driver(portAllocation = PortAllocation.Incremental(20000), isDebug = false, startNodesInProcess = true, extraCordappPackagesToScan = listOf("com.secLendModel")) {
            //Normal Users
            val arnoldParams = NodeParameters(providedName = ARNOLD, rpcUsers = arrayListOf(stdUser))
            val barryParams = NodeParameters(providedName = BARRY, rpcUsers = arrayListOf(stdUser))
            val colinParams = NodeParameters(providedName = COLIN, rpcUsers = arrayListOf(stdUser))
            val arnold = startNode(defaultParameters = arnoldParams)
            val barry = startNode(defaultParameters = barryParams)
            val colin = startNode(defaultParameters = colinParams)

            //Special Users (i.e asset issuers and oracles)
            val notaryParams = NodeParameters(providedName = NOTARY, advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type)))
            val notary = startNode(defaultParameters = notaryParams)
            //Stock issuer AND stock price oracle
            val exchangeParams = NodeParameters(providedName = EXCHANGE, rpcUsers = arrayListOf(specialUser),
                    advertisedServices = MARKET.plus(ServiceInfo(PriceType.type)))
            val exchange = startNode(defaultParameters = exchangeParams)
            //Cash issuer
            val centralbankParams = NodeParameters(providedName = CENTRALBANK, rpcUsers = arrayListOf(specialUser),
                    advertisedServices = CURRENCIES)
            val centralBank = startNode(defaultParameters = centralbankParams)
//            val oracle = startNode(ORACLE, advertisedServices = setOf(ServiceInfo(PriceType.type)))

            notaryNode = notary.get()
            arnoldNode = arnold.get()
            barryNode = barry.get()
            colinNode = colin.get()
            exchangeNode = exchange.get()
            centralNode = centralBank.get()
//            oracleNode = oracle.get()
            startWebserver(arnoldNode)

            setUpNodes()
            simulateTransactions()
            waitForAllNodesToFinish()
        }
</code>```

答: You need to close IntelliJ and clear out your gradle cache (under ~/.gradle on Mac).

Title: Node Driver startup issue V1

Body:
I am running into an issue after upgrading a custom cordapp from M13 to V1. I have a small test suite which launches nodes using the node driver, and after upgrading to version 1 I get an issue which seems to be caused by the cordadevcakeys.jks file being null (see the error stack below). To upgrade I simply changed the build gradle release version and gradle plugins version from 0.13.0 to 1.0.0 - I am not sure if there is a step I am missing here that could potentially cause this error? I have also pulled the latests version 1 Corda project locally - although I was under the impression that this step isnt needed.

[ERROR] 12:45:26,017 [main] (Driver.kt:396) driver.DriverDSL.genericDriver -
Driver shutting down because of exception
java.lang.ExceptionInInitializerError: null
at net.corda.testing.driver.DriverDSL.start(Driver.kt:796) ~[corda-node-driver-1.0.0.jar:?]
at net.corda.testing.driver.Driver.genericDriver(Driver.kt:393) [corda-node-driver-1.0.0.jar:?]
at net.corda.testing.driver.Driver.driver(Driver.kt:317) [corda-node-driver-1.0.0.jar:?]
at net.corda.testing.driver.Driver.driver$default(Driver.kt:314) [corda-node-driver-1.0.0.jar:?]
at src.DeploymentTestKt.main(DeploymentTest.kt:29) [main/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65) [idea_rt.jar:?]
Caused by: java.lang.IllegalStateException: ClassLoader.getSystemRes…ates/cordadevcakeys.jks") must not be null
at net.corda.testing.TestConstants$DEV_CA$2.invoke(TestConstants.kt:72) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.TestConstants$DEV_CA$2.invoke(TestConstants.kt) ~[corda-test-utils-1.0.0.jar:?]
at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130) ~[kotlin-stdlib-1.1.4.jar:1.1.4]
at net.corda.testing.TestConstants.getDEV_CA(TestConstants.kt) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.CoreTestUtils.getTestPartyAndCertificate$default(CoreTestUtils.kt:145) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.CoreTestUtils.getBOC_IDENTITY(CoreTestUtils.kt:75) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.CoreTestUtils.getBOC(CoreTestUtils.kt:76) ~[corda-test-utils-1.0.0.jar:?]
at net.corda.testing.CoreTestUtils.<clinit>(CoreTestUtils.kt:77) ~[corda-test-utils-1.0.0.jar:?]
... 10 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:65)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.corda.testing.CoreTestUtils
at net.corda.testing.driver.ShutdownManager.shutdown(Driver.kt:505)
at net.corda.testing.driver.DriverDSL.shutdown(Driver.kt:627)
at net.corda.testing.driver.Driver.genericDriver(Driver.kt:399)
at net.corda.testing.driver.Driver.driver(Driver.kt:317)
at net.corda.testing.driver.Driver.driver$default(Driver.kt:314)
at src.DeploymentTestKt.main(DeploymentTest.kt:29)
... 5 more
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: Could not initialize class net.corda.testing.CoreTestUtils
at net.corda.testing.driver.ShutdownManager.shutdown(Driver.kt:505)
at net.corda.testing.driver.DriverDSL.shutdown(Driver.kt:627)
at net.corda.testing.driver.Driver$genericDriver$shutdownHook$1.invoke(Driver.kt:391)
at net.corda.testing.driver.Driver$genericDriver$shutdownHook$1.invoke(Driver.kt)
at net.corda.nodeapi.internal.ShutdownHookKt$addShutdownHook$hook$1.run(ShutdownHook.kt:15)
at java.lang.Thread.run(Thread.java:748)

I can post the code I am using to launch the driver if need be, but by having a look at the cordapp-example it seems my method for starting the driver and nodes is correct, and it was working on M13.

*Edit, added in my gradle build and node driver code

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'maven-publish'
apply plugin: 'application'
apply plugin: 'net.corda.plugins.quasar-utils'

repositories {
    mavenLocal()
    jcenter()
    mavenCentral()
    maven { url 'https://dl.bintray.com/kotlin/exposed' }
    maven { url 'https://jitpack.io' }
}

sourceSets {
    main {
        resources {
            srcDir "../config/dev"
        }
    }
    test {
        resources {
            srcDir "../config/test"
        }
    }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
    compileOnly "co.paralleluniverse:capsule:1.0.1"
    compile 'net.sourceforge.plantuml:plantuml:8039'

    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
    testCompile "junit:junit:$junit_version"

    //Corda integration dependencies
    cordaCompile "net.corda:corda-core:$corda_release_version"
    cordaCompile "net.corda:corda-finance:$corda_release_version"
    cordaCompile "net.corda:corda-jackson:$corda_release_version"
    cordaCompile "net.corda:corda-jfx:$corda_release_version"
    cordaCompile "net.corda:corda-rpc:$corda_release_version"
    cordaCompile "net.corda:corda-node-api:$corda_release_version"
    cordaCompile "net.corda:corda-webserver-impl:$corda_release_version"
    cordaCompile "net.corda:corda-test-utils:$corda_release_version"
    testCompile "net.corda:corda-test-utils:$corda_release_version"
    cordaRuntime "net.corda:corda:$corda_release_version"
    cordaRuntime "net.corda:corda-webserver:$corda_release_version"
    cordaCompile "net.corda:corda-node-driver:$corda_release_version"
    //testCompile "net.corda:corda-node-driver:$corda_release_version"
    cordapp "net.corda:corda-finance:$corda_release_version"

//    cordaCompile "net.corda:corda-core:$corda_release_version"
//    cordaCompile "net.corda:corda-finance:$corda_release_version"
//    cordaCompile "net.corda:corda-jackson:$corda_release_version"
//    cordaCompile "net.corda:corda-rpc:$corda_release_version"
//    cordaCompile "net.corda:corda-node-api:$corda_release_version"
//    cordaCompile "net.corda:corda-webserver-impl:$corda_release_version"
//    cordaRuntime "net.corda:corda:$corda_release_version"
//    cordaRuntime "net.corda:corda-webserver:$corda_release_version"
//    testCompile "net.corda:corda-test-utils:$corda_release_version"
//    cordaCompile "net.corda:corda-node-driver:$corda_release_version"
//    testCompile "net.corda:corda-node-driver:$corda_release_version"

}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        languageVersion = "1.1"
        apiVersion = "1.1"
        jvmTarget = "1.8"
        javaParameters = true   // Useful for reflection.
    }
}

task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
    directory "./build/nodes"
    networkMap "CN=Controller,O=R3,OU=corda,L=London,C=UK"
    node {
        name "CN=Controller,O=R3,OU=corda,L=London,C=UK"
        advertisedServices = ["corda.notary.validating"]
        p2pPort 10002
        rpcPort 10003
        cordapps = ["secLendModel"]
    }
    node {
        name "CN=NodeA,O=NodeA,L=London,C=UK"
        advertisedServices = []
        p2pPort 10005
        rpcPort 10006
        webPort 10007
        cordapps = ["secLendModel"]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": []]]
    }
    node {
        name "CN=NodeB,O=NodeB,L=New York,C=US"
        advertisedServices = []
        p2pPort 10008
        rpcPort 10009
        webPort 10010
        cordapps = ["secLendModel"]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": []]]
    }
    node {
        name "CN=NodeC,O=NodeC,L=Paris,C=FR"
        advertisedServices = []
        p2pPort 10011
        rpcPort 10012
        webPort 10013
        cordapps = ["secLendModel"]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": []]]
    }
}

// TODO: Make into gradle plugin without any references to Jython
task installJythonDeps(dependsOn: ['build']) {
    project.copy {
        from project.configurations.runtime
        into "build/jythonDeps"
    }
}

installJythonDeps.shouldRunAfter build

idea {
    module {
        downloadJavadoc = true // defaults to false
        downloadSources = true
    }
}

publishing {
    publications {
        jarAndSources(MavenPublication) {
            from components.java
            artifactId 'secLendModel'

            artifact sourceJar
            artifact javadocJar
        }
    }
}

task runTemplateClientRPC(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'com.template.client.TemplateClientRPCKt'
    args 'localhost:10006'
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

and this is my node driver code

fun runSimulation() {
        driver(portAllocation = PortAllocation.Incremental(20000), isDebug = false, startNodesInProcess = true, extraCordappPackagesToScan = listOf("com.secLendModel")) {
            //Normal Users
            val arnoldParams = NodeParameters(providedName = ARNOLD, rpcUsers = arrayListOf(stdUser))
            val barryParams = NodeParameters(providedName = BARRY, rpcUsers = arrayListOf(stdUser))
            val colinParams = NodeParameters(providedName = COLIN, rpcUsers = arrayListOf(stdUser))
            val arnold = startNode(defaultParameters = arnoldParams)
            val barry = startNode(defaultParameters = barryParams)
            val colin = startNode(defaultParameters = colinParams)

            //Special Users (i.e asset issuers and oracles)
            val notaryParams = NodeParameters(providedName = NOTARY, advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type)))
            val notary = startNode(defaultParameters = notaryParams)
            //Stock issuer AND stock price oracle
            val exchangeParams = NodeParameters(providedName = EXCHANGE, rpcUsers = arrayListOf(specialUser),
                    advertisedServices = MARKET.plus(ServiceInfo(PriceType.type)))
            val exchange = startNode(defaultParameters = exchangeParams)
            //Cash issuer
            val centralbankParams = NodeParameters(providedName = CENTRALBANK, rpcUsers = arrayListOf(specialUser),
                    advertisedServices = CURRENCIES)
            val centralBank = startNode(defaultParameters = centralbankParams)
//            val oracle = startNode(ORACLE, advertisedServices = setOf(ServiceInfo(PriceType.type)))

            notaryNode = notary.get()
            arnoldNode = arnold.get()
            barryNode = barry.get()
            colinNode = colin.get()
            exchangeNode = exchange.get()
            centralNode = centralBank.get()
//            oracleNode = oracle.get()
            startWebserver(arnoldNode)

            setUpNodes()
            simulateTransactions()
            waitForAllNodesToFinish()
        }


问:
Turn this sub into a function so that I could update all the other charts on Sheet2 without having to repeat the code
```<code>Private Sub updateChart1()

   Dim month
   Dim year
   Dim stringToFind
   Dim newRange
   Dim foundString
   Dim newRange1
   Dim newrange2

   'Assign a value to the month and the year
   month = VBA.DateTime.month(Date)
   year = VBA.DateTime.year(Date)

   'Make the search for string equal to the month + year variables
   stringToFind = month & "/" & year

   'Declare a range where you will look for the month and year
   Set newRange = Worksheets("Sheet1").Range("C16:Z16")

   'Search for the month and year
   Set foundString = newRange.Find(stringToFind)

   'Once the correct date has been found, resize the range to be the new data source
   Set newRange1 = foundString.Offset(0, -12)

   Set newrange2 = newRange1.Resize(2, 12)

   'Update the chart with the new data source
   Worksheets("Sheet2").ChartObjects("Chart1").Chart.SetSourceData Source:=newrange2

End Sub
</code>```

I am sure there must be a better way than repeating this code, but am not sure how to turn it into a repeatable function given that newRange will be different for each chart - any ideas?

答:
You may just pass newRange and worksheet reference as argument.

```<code>Private Sub updateChart1(newRange As Range)

'I decided that only Range in argument list is enough. You may refer to the worksheet by newRange.Parent.

Dim month
Dim year
Dim stringToFind
Dim foundString
Dim newRange1
Dim newrange2
</code>```

remove the line;

```<code>Set newRange = Worksheets("Sheet1").Range("C16:Z16")
</code>```

You then can use this sub in your code, letting it do the job for any sheet and range you want.

Body:
Private Sub updateChart1()

   Dim month
   Dim year
   Dim stringToFind
   Dim newRange
   Dim foundString
   Dim newRange1
   Dim newrange2

   'Assign a value to the month and the year
   month = VBA.DateTime.month(Date)
   year = VBA.DateTime.year(Date)

   'Make the search for string equal to the month + year variables
   stringToFind = month & "/" & year

   'Declare a range where you will look for the month and year
   Set newRange = Worksheets("Sheet1").Range("C16:Z16")

   'Search for the month and year
   Set foundString = newRange.Find(stringToFind)

   'Once the correct date has been found, resize the range to be the new data source
   Set newRange1 = foundString.Offset(0, -12)

   Set newrange2 = newRange1.Resize(2, 12)

   'Update the chart with the new data source
   Worksheets("Sheet2").ChartObjects("Chart1").Chart.SetSourceData Source:=newrange2

End Sub

I am sure there must be a better way than repeating this code, but am not sure how to turn it into a repeatable function given that newRange will be different for each chart - any ideas?

Body:
You may just pass newRange and worksheet reference as argument.

Private Sub updateChart1(newRange As Range)

'I decided that only Range in argument list is enough. You may refer to the worksheet by newRange.Parent.

Dim month
Dim year
Dim stringToFind
Dim foundString
Dim newRange1
Dim newrange2

remove the line;

Set newRange = Worksheets("Sheet1").Range("C16:Z16")

You then can use this sub in your code, letting it do the job for any sheet and range you want.

ContentLicense: CC BY-SA 4.0