问:
Android Device Monitor will not launch, either from Android Studio or from Terminal -- UnsupportedClassVersionError
I am getting the following error when trying to launch Android Device Monitor from the Tools window in Android Studio on a Mac.

and when I open the log file I find an error report very similar to the other SO questions similar to this, esp this one.  However, using sudo did not work for me, although I get similar, though much shorter, error data:

```<code>Macs-MBP:tools macuser$ sudo ./monitor
Password:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/archquery/Main : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
./monitor: line 41: /Users/macuser/Library/Android/sdk/tools/lib/monitor-/monitor.app/Contents/MacOS/monitor: No such file or directory
./monitor: line 41: exec: /Users/macuser/Library/Android/sdk/tools/lib/monitor-/monitor.app/Contents/MacOS/monitor: cannot execute: No such file or directory
</code>```

Backstory: After doing a complete, new Android Studio installation on this laptop (El Capitan) I attempted to launch the monitor from inside the IDE. It complained that running it required Java 1.6.  So I installed Java 6. Then when I tried it I got the error message above.

I get the following when I ran from Terminal java_home -V

```<code>Matching Java Virtual Machines (2):
    1.6.0_65-b14-468, x86_64:   "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-468, i386: "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
</code>```

The contents of the log file are (unfortunately had to cull some because of text entry limitations for post):

```<code>!SESSION 2017-03-07 14:46:16.923 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_65
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments:  -keyring /Users/macuser/.eclipse_keyring -showlocation
Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -data @noDefault -keyring /Users/macuser/.eclipse_keyring -showlocation

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.397
!MESSAGE Bundle reference:file:org.apache.ant_1.8.3.v201301120609/@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.400
!MESSAGE Bundle reference:file:org.apache.jasper.glassfish_2.2.2.v201205150955.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.401
!MESSAGE Bundle reference:file:org.apache.lucene.core_2.9.1.v201101211721.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.424
!MESSAGE Bundle reference:file:org.eclipse.help.base_3.6.101.v201302041200.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.425
!MESSAGE Bundle reference:file:org.eclipse.help.ui_3.5.201.v20130108-092756.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.425
!MESSAGE Bundle reference:file:org.eclipse.help.webapp_3.6.101.v20130116-182509.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.426
!MESSAGE Bundle reference:file:org.eclipse.jetty.server_8.1.3.v20120522.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.429
!MESSAGE Bundle reference:file:org.eclipse.platform.doc.user_4.2.2.v20130121-200410.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.430
!MESSAGE Bundle reference:file:org.eclipse.team.core_3.6.100.v20120524-0627.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.430
!MESSAGE Bundle reference:file:org.eclipse.team.ui_3.6.201.v20130125-135424.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.431
!MESSAGE Bundle reference:file:org.eclipse.ui.cheatsheets_3.4.200.v20120521-2344.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.432
!MESSAGE Bundle reference:file:org.eclipse.ui.intro_3.4.200.v20120521-2344.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.924
!MESSAGE An error occurred while automatically activating bundle com.android.ide.eclipse.monitor (4).
!STACK 0
org.osgi.framework.BundleException: The activator com.android.ide.eclipse.monitor.MonitorPlugin for bundle com.android.ide.eclipse.monitor is invalid
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:172)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:679)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
    at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
    at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:469)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:464)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:340)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1212)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:174)
    at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
    at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:191)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
Caused by: java.lang.UnsupportedClassVersionError: com/android/prefs/AndroidLocation$AndroidLocationException : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:632)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:614)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:568)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:492)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:465)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at com.android.ide.eclipse.monitor.MonitorPlugin.<clinit>(MonitorPlugin.java:28)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:357)
    at java.lang.Class.newInstance(Class.java:310)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:167)
    ... 33 more

!ENTRY org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.http.jetty_3.0.1.v20121109-203239.jar was not resolved.
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.ssl_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.nio_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.session_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.bio_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.handler_[8.0.0,9.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.ltk.ui.refactoring_3.7.0.v20120523-1543.jar was not resolved.
!SUBENTRY 2 org.eclipse.ltk.ui.refactoring 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.eclipse.team.core_[3.4.100,4.0.0).
!SUBENTRY 2 org.eclipse.ltk.ui.refactoring 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.eclipse.team.ui_[3.4.100,4.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.platform_4.2.2.v201302041200/ was not resolved.
!SUBENTRY 2 org.eclipse.platform 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.eclipse.ui.intro_[3.2.0,4.0.0).
!SUBENTRY 2 org.eclipse.platform 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required capability Require-Capability: osgi.ee; filter="(|(&(osgi.ee=JavaSE)(version=1.4))(&(osgi.ee=CDC/Foundation)(version=1.0))(&(osgi.ee=JavaSE)(version=1.3)))".
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.ui.intro.universal_3.2.600.v20120912-155524/ was not resolved.
!SUBENTRY 2 org.eclipse.ui.intro.universal 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.eclipse.ui.intro_[3.4.0,4.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.jsp.jasper_1.0.400.v20120912-130548.jar was not resolved.
!SUBENTRY 2 org.eclipse.equinox.jsp.jasper 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.apache.jasper.servlet_[0.0.0,6.0.0).
!SUBENTRY 2 org.eclipse.equinox.jsp.jasper 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required capability Require-Capability: osgi.ee; filter="(|(&(osgi.ee=CDC/Foundation)(version=1.0))(&(osgi.ee=JavaSE)(version=1.3)))".
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.apache.lucene_2.9.1.v201101211721.jar was not resolved.
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.apache.lucene.core_[2.9.1,3.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.jetty.security_8.1.3.v20120522.jar was not resolved.
!SUBENTRY 2 org.eclipse.jetty.security 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.security 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.handler_[8.1.0,9.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.apache.lucene.analysis_2.9.1.v201101211721.jar was not resolved.
!SUBENTRY 2 org.apache.lucene.analysis 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.apache.lucene.core_[2.9.1,3.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.jetty.servlet_8.1.3.v20120522.jar was not resolved.
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server.handler_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server.session_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server.nio_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server.ssl_[8.1.0,9.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.018
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.jsp.jasper.registry_1.0.300.v20120912-130548.jar was not resolved.
!SUBENTRY 2 org.eclipse.equinox.jsp.jasper.registry 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing required capability Require-Capability: osgi.ee; filter="(|(&(osgi.ee=CDC/Foundation)(version=1.0))(&(osgi.ee=JavaSE)(version=1.3)))".

!ENTRY org.eclipse.osgi 2 0 2017-03-07 14:46:18.037
!MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists:
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.037
!MESSAGE Bundle org.apache.lucene_2.9.1.v201101211721 [24] was not resolved.
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing required bundle org.apache.lucene.core_[2.9.1,3.0.0).
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing optionally required bundle org.apache.lucene.analysis_[2.9.1,3.0.0).
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing optionally required bundle org.apache.lucene.highlighter_[2.9.1,3.0.0).
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing optionally required bundle org.apache.lucene.memory_[2.9.1,3.0.0).
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing optionally required bundle org.apache.lucene.queries_[2.9.1,3.0.0).

. . .

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:18.041
!MESSAGE Application error
!STACK 1
org.eclipse.core.runtime.CoreException: Plug-in com.android.ide.eclipse.monitor was unable to load class com.android.ide.eclipse.monitor.MonitorApplication.
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:176)
    at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
    at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:191)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
Caused by: org.osgi.framework.BundleException: The activator com.android.ide.eclipse.monitor.MonitorPlugin for bundle com.android.ide.eclipse.monitor is invalid
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:172)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:679)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
    at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
    at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
    ... 27 more
Caused by: java.lang.UnsupportedClassVersionError: com/android/prefs/AndroidLocation$AndroidLocationException : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:632)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:614)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:568)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:492)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:465)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at com.android.ide.eclipse.monitor.MonitorPlugin.<clinit>(MonitorPlugin.java:28)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:357)
    at java.lang.Class.newInstance(Class.java:310)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:167)
    ... 33 more
</code>```

答:
Confusingly I didn't have Java 8 installed in a shared location (only the bundled version in Android Studio). Installing it through homebrew solved my problem.</p>

```<code>brew cask install java

$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
</code>```

Body:
I am getting the following error when trying to launch Android Device Monitor from the Tools window in Android Studio on a Mac.

and when I open the log file I find an error report very similar to the other SO questions similar to this, esp this one.  However, using sudo did not work for me, although I get similar, though much shorter, error data:

Macs-MBP:tools macuser$ sudo ./monitor
Password:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/archquery/Main : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
./monitor: line 41: /Users/macuser/Library/Android/sdk/tools/lib/monitor-/monitor.app/Contents/MacOS/monitor: No such file or directory
./monitor: line 41: exec: /Users/macuser/Library/Android/sdk/tools/lib/monitor-/monitor.app/Contents/MacOS/monitor: cannot execute: No such file or directory

Backstory: After doing a complete, new Android Studio installation on this laptop (El Capitan) I attempted to launch the monitor from inside the IDE. It complained that running it required Java 1.6.  So I installed Java 6. Then when I tried it I got the error message above.

I get the following when I ran from Terminal java_home -V

Matching Java Virtual Machines (2):
    1.6.0_65-b14-468, x86_64:   "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-468, i386: "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

The contents of the log file are (unfortunately had to cull some because of text entry limitations for post):

!SESSION 2017-03-07 14:46:16.923 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_65
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
Framework arguments:  -keyring /Users/macuser/.eclipse_keyring -showlocation
Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -data @noDefault -keyring /Users/macuser/.eclipse_keyring -showlocation

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.397
!MESSAGE Bundle reference:file:org.apache.ant_1.8.3.v201301120609/@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.400
!MESSAGE Bundle reference:file:org.apache.jasper.glassfish_2.2.2.v201205150955.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.401
!MESSAGE Bundle reference:file:org.apache.lucene.core_2.9.1.v201101211721.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.424
!MESSAGE Bundle reference:file:org.eclipse.help.base_3.6.101.v201302041200.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.425
!MESSAGE Bundle reference:file:org.eclipse.help.ui_3.5.201.v20130108-092756.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.425
!MESSAGE Bundle reference:file:org.eclipse.help.webapp_3.6.101.v20130116-182509.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.426
!MESSAGE Bundle reference:file:org.eclipse.jetty.server_8.1.3.v20120522.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.429
!MESSAGE Bundle reference:file:org.eclipse.platform.doc.user_4.2.2.v20130121-200410.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.430
!MESSAGE Bundle reference:file:org.eclipse.team.core_3.6.100.v20120524-0627.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.430
!MESSAGE Bundle reference:file:org.eclipse.team.ui_3.6.201.v20130125-135424.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.431
!MESSAGE Bundle reference:file:org.eclipse.ui.cheatsheets_3.4.200.v20120521-2344.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.432
!MESSAGE Bundle reference:file:org.eclipse.ui.intro_3.4.200.v20120521-2344.jar@4 not found.

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:17.924
!MESSAGE An error occurred while automatically activating bundle com.android.ide.eclipse.monitor (4).
!STACK 0
org.osgi.framework.BundleException: The activator com.android.ide.eclipse.monitor.MonitorPlugin for bundle com.android.ide.eclipse.monitor is invalid
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:172)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:679)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
    at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
    at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:469)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:464)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:340)
    at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1212)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:174)
    at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
    at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:191)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
Caused by: java.lang.UnsupportedClassVersionError: com/android/prefs/AndroidLocation$AndroidLocationException : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:632)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:614)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:568)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:492)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:465)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at com.android.ide.eclipse.monitor.MonitorPlugin.<clinit>(MonitorPlugin.java:28)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:357)
    at java.lang.Class.newInstance(Class.java:310)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:167)
    ... 33 more

!ENTRY org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.http.jetty_3.0.1.v20121109-203239.jar was not resolved.
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.ssl_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.nio_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.session_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.bio_[8.0.0,9.0.0).
!SUBENTRY 2 org.eclipse.equinox.http.jetty 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.handler_[8.0.0,9.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.ltk.ui.refactoring_3.7.0.v20120523-1543.jar was not resolved.
!SUBENTRY 2 org.eclipse.ltk.ui.refactoring 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.eclipse.team.core_[3.4.100,4.0.0).
!SUBENTRY 2 org.eclipse.ltk.ui.refactoring 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.eclipse.team.ui_[3.4.100,4.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.platform_4.2.2.v201302041200/ was not resolved.
!SUBENTRY 2 org.eclipse.platform 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.eclipse.ui.intro_[3.2.0,4.0.0).
!SUBENTRY 2 org.eclipse.platform 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required capability Require-Capability: osgi.ee; filter="(|(&(osgi.ee=JavaSE)(version=1.4))(&(osgi.ee=CDC/Foundation)(version=1.0))(&(osgi.ee=JavaSE)(version=1.3)))".
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.ui.intro.universal_3.2.600.v20120912-155524/ was not resolved.
!SUBENTRY 2 org.eclipse.ui.intro.universal 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.eclipse.ui.intro_[3.4.0,4.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.jsp.jasper_1.0.400.v20120912-130548.jar was not resolved.
!SUBENTRY 2 org.eclipse.equinox.jsp.jasper 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.apache.jasper.servlet_[0.0.0,6.0.0).
!SUBENTRY 2 org.eclipse.equinox.jsp.jasper 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required capability Require-Capability: osgi.ee; filter="(|(&(osgi.ee=CDC/Foundation)(version=1.0))(&(osgi.ee=JavaSE)(version=1.3)))".
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.apache.lucene_2.9.1.v201101211721.jar was not resolved.
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.apache.lucene.core_[2.9.1,3.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.jetty.security_8.1.3.v20120522.jar was not resolved.
!SUBENTRY 2 org.eclipse.jetty.security 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.security 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing imported package org.eclipse.jetty.server.handler_[8.1.0,9.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.apache.lucene.analysis_2.9.1.v201101211721.jar was not resolved.
!SUBENTRY 2 org.apache.lucene.analysis 2 0 2017-03-07 14:46:18.017
!MESSAGE Missing required bundle org.apache.lucene.core_[2.9.1,3.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.017
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.jetty.servlet_8.1.3.v20120522.jar was not resolved.
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server.handler_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server.session_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server.nio_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server_[8.1.0,9.0.0).
!SUBENTRY 2 org.eclipse.jetty.servlet 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing imported package org.eclipse.jetty.server.ssl_[8.1.0,9.0.0).
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.018
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.jsp.jasper.registry_1.0.300.v20120912-130548.jar was not resolved.
!SUBENTRY 2 org.eclipse.equinox.jsp.jasper.registry 2 0 2017-03-07 14:46:18.018
!MESSAGE Missing required capability Require-Capability: osgi.ee; filter="(|(&(osgi.ee=CDC/Foundation)(version=1.0))(&(osgi.ee=JavaSE)(version=1.3)))".

!ENTRY org.eclipse.osgi 2 0 2017-03-07 14:46:18.037
!MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists:
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-03-07 14:46:18.037
!MESSAGE Bundle org.apache.lucene_2.9.1.v201101211721 [24] was not resolved.
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing required bundle org.apache.lucene.core_[2.9.1,3.0.0).
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing optionally required bundle org.apache.lucene.analysis_[2.9.1,3.0.0).
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing optionally required bundle org.apache.lucene.highlighter_[2.9.1,3.0.0).
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing optionally required bundle org.apache.lucene.memory_[2.9.1,3.0.0).
!SUBENTRY 2 org.apache.lucene 2 0 2017-03-07 14:46:18.037
!MESSAGE Missing optionally required bundle org.apache.lucene.queries_[2.9.1,3.0.0).

. . .

!ENTRY org.eclipse.osgi 4 0 2017-03-07 14:46:18.041
!MESSAGE Application error
!STACK 1
org.eclipse.core.runtime.CoreException: Plug-in com.android.ide.eclipse.monitor was unable to load class com.android.ide.eclipse.monitor.MonitorApplication.
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:176)
    at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
    at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:191)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
Caused by: org.osgi.framework.BundleException: The activator com.android.ide.eclipse.monitor.MonitorPlugin for bundle com.android.ide.eclipse.monitor is invalid
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:172)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:679)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
    at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
    at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
    ... 27 more
Caused by: java.lang.UnsupportedClassVersionError: com/android/prefs/AndroidLocation$AndroidLocationException : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:632)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:614)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:568)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:492)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:465)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at com.android.ide.eclipse.monitor.MonitorPlugin.<clinit>(MonitorPlugin.java:28)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:357)
    at java.lang.Class.newInstance(Class.java:310)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:167)
    ... 33 more

Body:
Confusingly I didn't have Java 8 installed in a shared location (only the bundled version in Android Studio). Installing it through homebrew solved my problem.

brew cask install java

$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


来源: stackexchange

问:
Ansible - get variables from group_vars and host_vars together into a list
I am trying to get from an inventory group a list of IP addresses instead of host names. These IP addresses are already in my hostvars but I cant make them matching a list from their group name.

Here is my original playbook :

```<code>- name: Install Kafka
  hosts: kafka
  roles:
    - role: kafka
      kafka_hosts: "{{ groups['kafka'] | list }}"
      kafka_zookeeper_hosts: "{{ groups['zookeeper'] | list }}"
</code>```

As you can see, kafka_hosts and kafka_zookeeper_hosts are lists.
The result of this playbook to my servers configuration is correct :

```<code>/etc/kafka/consumer.properties:zookeeper.connect=opo-4:2181,opo-5:2181,opo-6:2181
/etc/kafka/producer.properties:metadata.broker.list=opo-1:9092,opo-2:9092,opo-3:9092
</code>```

Unfortunately, this configuration does not work for all my servers because of DNS issues. I need a list of IP addresses instead of hostnames.

If I set manually the IP addresses in my playbook, my configuration works, unfortunately not dynamically :

```<code>  kafka_hosts:
    - 192.168.48.1
    - 192.168.48.2
    - 192.168.48.3
  kafka_zookeeper_hosts:
    - 192.168.48.4
    - 192.168.48.5
    - 192.168.48.6
</code>```

And the result on my servers make it working :

```<code>/etc/kafka/consumer.properties:zookeeper.connect=192.168.48.4:2181,192.168.48.5:2181,192.168.48.6:2181
/etc/kafka/producer.properties:metadata.broker.list=192.168.48.1:9092,192.168.48.2:9092,192.168.48.3:9092
</code>```

In this configuration I have to maintain manually my groups and my playbook with the same information. So I would like to get the hostvars from groups kafka and zookeeper.

Here are hostvars and groups, defined in the main inventory file :

```<code>[opo]
opo-1 ansible_host=192.168.48.1
opo-2 ansible_host=192.168.48.2
...
opo-6 ansible_host=192.168.48.6

[zookeeper]
opo-1
opo-2
opo-3

[kafka]
opo-4
opo-5
opo-6
</code>```

What I have tried - based on answers found on stackoverflow from similar issues :

kafka_hosts: "{{ groups[['kafka']['ansible_host']] | list }}"

kafka_hosts: "{{ [hostvars[groups['kafka'][0]]['ansible_host']] | list }}"  # the list contains only the first ip address

kafka_hosts: "{{ [hostvars[groups['kafka']]['ansible_host']] | list }}"

kafka_hosts: "{{ hostvars[groups['kafka']].ansible_host | list }}"

kafka_hosts: "{{ [hostvars.[groups['kafka']].ansible_host]  | list }}"

kafka_hosts: "{{ groups['kafka'].ansible_host  | list }}"

None of them gives the expected list of IP addresses.

答:
You need to use extract and map combination:

```<code>kafka_hosts: "{{ groups['kafka'] | map('extract',hostvars,'ansible_host') | list }}"
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I am trying to get from an inventory group a list of IP addresses instead of host names. These IP addresses are already in my hostvars but I cant make them matching a list from their group name.

Here is my original playbook :

- name: Install Kafka
  hosts: kafka
  roles:
    - role: kafka
      kafka_hosts: "{{ groups['kafka'] | list }}"
      kafka_zookeeper_hosts: "{{ groups['zookeeper'] | list }}"

As you can see, kafka_hosts and kafka_zookeeper_hosts are lists.
The result of this playbook to my servers configuration is correct :

/etc/kafka/consumer.properties:zookeeper.connect=opo-4:2181,opo-5:2181,opo-6:2181
/etc/kafka/producer.properties:metadata.broker.list=opo-1:9092,opo-2:9092,opo-3:9092

Unfortunately, this configuration does not work for all my servers because of DNS issues. I need a list of IP addresses instead of hostnames.

If I set manually the IP addresses in my playbook, my configuration works, unfortunately not dynamically :

  kafka_hosts:
    - 192.168.48.1
    - 192.168.48.2
    - 192.168.48.3
  kafka_zookeeper_hosts:
    - 192.168.48.4
    - 192.168.48.5
    - 192.168.48.6

And the result on my servers make it working :

/etc/kafka/consumer.properties:zookeeper.connect=192.168.48.4:2181,192.168.48.5:2181,192.168.48.6:2181
/etc/kafka/producer.properties:metadata.broker.list=192.168.48.1:9092,192.168.48.2:9092,192.168.48.3:9092

In this configuration I have to maintain manually my groups and my playbook with the same information. So I would like to get the hostvars from groups kafka and zookeeper.

Here are hostvars and groups, defined in the main inventory file :

[opo]
opo-1 ansible_host=192.168.48.1
opo-2 ansible_host=192.168.48.2
...
opo-6 ansible_host=192.168.48.6

[zookeeper]
opo-1
opo-2
opo-3

[kafka]
opo-4
opo-5
opo-6

What I have tried - based on answers found on stackoverflow from similar issues :

kafka_hosts: "{{ groups[['kafka']['ansible_host']] | list }}"

kafka_hosts: "{{ [hostvars[groups['kafka'][0]]['ansible_host']] | list }}"  # the list contains only the first ip address

kafka_hosts: "{{ [hostvars[groups['kafka']]['ansible_host']] | list }}"

kafka_hosts: "{{ hostvars[groups['kafka']].ansible_host | list }}"

kafka_hosts: "{{ [hostvars.[groups['kafka']].ansible_host]  | list }}"

kafka_hosts: "{{ groups['kafka'].ansible_host  | list }}"

None of them gives the expected list of IP addresses.

Body:
You need to use extract and map combination:

kafka_hosts: "{{ groups['kafka'] | map('extract',hostvars,'ansible_host') | list }}"

ContentLicense: CC BY-SA 4.0


问:
Get String value from JSON document

valeurs_d = "";
for (var i = 0; i < keys.length -1 ; i++)
valeurs_d += + event[keys[i]] + ", ";
var str5 = ",";
var str6 = str5.concat(valeurs_d);
var valeurs = str6.substring (0, str6.length - 2);
console.log(valeurs);```
</div>
</div>
</p>

<p>I have a json document like this :</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code> {
  "temperature" : 12.45,
  "lala" : 45.75,
  "humidite" : 45.78,
  "toto" : "gvvgvh",
  "topic" : "sk1_001/data"
 }</code>```

The problem when I retrieve the values. I have the following result: 12.45, 45.75, 45.78, NaN!

I want to retrieve my string instead of NaN, How ?

edit : Thank you, it's donne, but I hava annoter question :

Typeof in Javascript returns number or string, or I want to return varchar for string, and double for number.

I need this to write on my Apache Cassandra database in node.js.

How can I proceed to return varchar and double ?

答:
As I understand, you just want a list of all the values in your object. This should do the trick :

let obj = {
  "temperature" : 12.45,
  "lala" : 45.75,
  "humidite" : 45.78,
  "toto" : "gvvgvh",
  "topic" : "sk1_001/data"
 }

let values = Object.keys(obj).map( key => obj[key] )

console.log(values)```

So you get all values in an array, but if you want a string, you can always do values.join(",").

Title: Get String value from JSON document

Body:
valeurs_d = "";
for (var i = 0; i < keys.length -1 ; i++)
valeurs_d += + event[keys[i]] + ", ";
var str5 = ",";
var str6 = str5.concat(valeurs_d);
var valeurs = str6.substring (0, str6.length - 2);
console.log(valeurs);

I have a json document like this :

 {
  "temperature" : 12.45,
  "lala" : 45.75,
  "humidite" : 45.78,
  "toto" : "gvvgvh",
  "topic" : "sk1_001/data"
 }

The problem when I retrieve the values. I have the following result: 12.45, 45.75, 45.78, NaN!

I want to retrieve my string instead of NaN, How ?

edit : Thank you, it's donne, but I hava annoter question :

Typeof in Javascript returns number or string, or I want to return varchar for string, and double for number.

I need this to write on my Apache Cassandra database in node.js.

How can I proceed to return varchar and double ?

Body:
As I understand, you just want a list of all the values in your object. This should do the trick :

let obj = {
  "temperature" : 12.45,
  "lala" : 45.75,
  "humidite" : 45.78,
  "toto" : "gvvgvh",
  "topic" : "sk1_001/data"
 }

let values = Object.keys(obj).map( key => obj[key] )

console.log(values)

So you get all values in an array, but if you want a string, you can always do values.join(",").


问:
IntelliJ Terminal Output Text Highlighting Blue
I just recently installed IntelliJ and when running any commands in the terminal I get an annoying blue highlighting of the output. I can't see where this is happening in the settings, nor can I find a similar problem online.

答: Seems you have some custom colors set for screen text and background in Windows cmd console properties. See IDEA-145236 and IDEA-124182 for details. The solution is to set cmd console colors back to defaults - by either editing the registry key or by modifying default cmd console properties</p>


问:
document.getElementById class applies to the whole array instead of each element

elements of the array
```
</div>
</div>
</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>for(var i = 0; i < myarray.length; i++)
{
 var sr = (function(val) {
        btn = document.createElement('button');
        btn.data = val;
        btn.innerHTML = val;
        btn.addEventListener('click', checkAnswer);
        document.body.appendChild(btn);
  return btn.data = val;
    })//(myarray[i]);
document.getElementById("sr").innerHTML = myarray;
}</code>```

With this code the elements of the array appear in the html span. I want each element to appear as a button, as defined in the class "btn". However, the class changes the style of the array as a whole, not as single buttons. What is the correct way to define the style of each button?

I tried document.getElementById("sr").innerHTML = myarray.class="btn";. It does not work. Definitely not the correct syntax. Any idea?

答:
Is this what you want to achieve?

let container = document.getElementById('sr');
let array = ['element1', 'element2', 'element3'];

function checkAnswer () {
  console.log('Selected answer: ', this.textContent);
}

for (let i = 0; i < array.length; i++) {
  let button = document.createElement('button');
  button.textContent = array[i];
  button.addEventListener('click', checkAnswer);
  container.appendChild(button);
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><p><span id="sr" class="btn"></span></p></code>```

Body:
elements of the array

for(var i = 0; i < myarray.length; i++)
{
 var sr = (function(val) {
        btn = document.createElement('button');
        btn.data = val;
        btn.innerHTML = val;
        btn.addEventListener('click', checkAnswer);
        document.body.appendChild(btn);
  return btn.data = val;
    })//(myarray[i]);
document.getElementById("sr").innerHTML = myarray;
}

With this code the elements of the array appear in the html span. I want each element to appear as a button, as defined in the class "btn". However, the class changes the style of the array as a whole, not as single buttons. What is the correct way to define the style of each button?

I tried document.getElementById("sr").innerHTML = myarray.class="btn";. It does not work. Definitely not the correct syntax. Any idea?

Body:
Is this what you want to achieve?

let container = document.getElementById('sr');
let array = ['element1', 'element2', 'element3'];

function checkAnswer () {
  console.log('Selected answer: ', this.textContent);
}

for (let i = 0; i < array.length; i++) {
  let button = document.createElement('button');
  button.textContent = array[i];
  button.addEventListener('click', checkAnswer);
  container.appendChild(button);
}

<p><span id="sr" class="btn"></span></p>


问:
How to find given 2D point position based on axis system
I have a axis system(origin,u direction,v direction).How to know given 2D point lie on the line which is used to denote the u or v direction line(ie, u=0 or v =0)?</p>

答:
The axis OU has equation

```<code>Uy.(X - Ox) - Ux.(Y - Oy) = 0
</code>```

and similarly for OV

```<code>Vy.(X - Ox) - Vx.(Y - Oy) = 0
</code>```

Because of rounding errors, strict equality to zero will not hold, but if the vectors U and V are normalized,

```<code>|Uy.(X - Ox) - Ux.(Y - Oy)|
</code>```

and

```<code>|Vy.(X - Ox) - Vx.(Y - Oy)|
</code>```

are the shortest distances from the point (X, Y) to the axes.

Body:
The axis OU has equation

Uy.(X - Ox) - Ux.(Y - Oy) = 0

and similarly for OV

Vy.(X - Ox) - Vx.(Y - Oy) = 0

Because of rounding errors, strict equality to zero will not hold, but if the vectors U and V are normalized,

|Uy.(X - Ox) - Ux.(Y - Oy)|

and

|Vy.(X - Ox) - Vx.(Y - Oy)|

are the shortest distances from the point (X, Y) to the axes.


答:
If I understand you correctly, you want to add btn class to your dynamically created buttons with myarray elements.

What is the correct way to define the style of each button?

I tried document.getElementById("sr").innerHTML = myarray.class="btn";

You can use element.classList.add('your-class');

var myarray = ["Array", "elements"]; //let's say
for (var i = 0; i < myarray.length; i++) {
  var sr = (function(val) {
    btn = document.createElement('button');
    btn.data = val;
    btn.innerHTML = val;
    btn.classList.add("btn")
    btn.addEventListener('click', checkAnswer);
    document.body.appendChild(btn);
    return btn.data = val;
  })(myarray[i]);
  //document.getElementById("sr").innerHTML = myarray;//I don't know why this line here?
}

function checkAnswer(e){
}```

Title: document.getElementById class applies to the whole array instead of each element


问:
Difference between !! and ! in JavaScript
I have encountered those operators that are checking for user.rank property:

```<code><div ng-show="!!user.rank">
    {{user.rank}}
</div>
<button ng-show="!user.rank"  ng-click="addRank(user)">Add Rank</button>
</code>```

How are they different and what can we use instead?

答:
What is the !! (not not) operator in JavaScript?

From the JS wiki on SO

Regarding !!:

"Coerces oObject to boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true."

"It converts a nonboolean to an inverted boolean (for instance, !5 would be false, since 5 is a non-false value in JS), then boolean-inverts that so you get the original value as a boolean (so !!5 would be true)"

"So !! is not an operator, it's just the ! operator twice."

Body:
I have encountered those operators that are checking for user.rank property:

    {{user.rank}}

<button ng-show="!user.rank"  ng-click="addRank(user)">Add Rank</button>

How are they different and what can we use instead?


问:
Creating cx_Freeze exe with Numpy for Python
Im trying to create a basic exe using cx_Freeze. It works for .py programs that don't have numpy but I can't get one made correctly with numpy.

*Any ideas on how to fix this? is there something i need to include in my setup.py?

When I go to run the exe it says:

```<code>           c:\Python32\Scripts\dist>Assignment4_5.exe
           Traceback (most recent call last):
     File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
     7, in <module>
     exec(code, m.__dict__)
     File "c:\Python32\Assignment4_5.py", line 6, in <module>
     import numpy as np
     File "C:\Python32\lib\site-packages\numpy\__init__.py", line 137, in <module>
     from . import add_newdocs
     File "C:\Python32\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>

     from numpy.lib import add_newdoc
     File "C:\Python32\lib\site-packages\numpy\lib\__init__.py", line 17, in <modul
     e>
    from .npyio import *
    File "C:\Python32\lib\site-packages\numpy\lib\npyio.py", line 6, in <module>
    from . import format
    ImportError: cannot import name format

   c:\Python32\Scripts\dist>
</code>```

Setup.py:

```<code>   from cx_Freeze import setup, Executable

   includeDependencies = []

   setup(
        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        executables = [Executable("Assignment4_5.py")]
        )
</code>```

答:
Numpy seems to be a little confusing to cx_Freeze so you need to declare it explicitly. As referenced in the docs

Here is your solution:

```<code>   from cx_Freeze import setup, Executable

   build_exe_options = {"packages": ["numpy"]}

   setup(
        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        options = {"build_exe": build_exe_options},
        executables = [Executable("Assignment4_5.py")]
        )
</code>```

Body:
Im trying to create a basic exe using cx_Freeze. It works for .py programs that don't have numpy but I can't get one made correctly with numpy.

*Any ideas on how to fix this? is there something i need to include in my setup.py?

When I go to run the exe it says:

           c:\Python32\Scripts\dist>Assignment4_5.exe
           Traceback (most recent call last):
     File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
     7, in <module>
     exec(code, m.__dict__)
     File "c:\Python32\Assignment4_5.py", line 6, in <module>
     import numpy as np
     File "C:\Python32\lib\site-packages\numpy\__init__.py", line 137, in <module>
     from . import add_newdocs
     File "C:\Python32\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>

     from numpy.lib import add_newdoc
     File "C:\Python32\lib\site-packages\numpy\lib\__init__.py", line 17, in <modul
     e>
    from .npyio import *
    File "C:\Python32\lib\site-packages\numpy\lib\npyio.py", line 6, in <module>
    from . import format
    ImportError: cannot import name format

   c:\Python32\Scripts\dist>

Setup.py:

   from cx_Freeze import setup, Executable

   includeDependencies = []

   setup(
        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        executables = [Executable("Assignment4_5.py")]
        )

Body:
Numpy seems to be a little confusing to cx_Freeze so you need to declare it explicitly. As referenced in the docs

Here is your solution:

   from cx_Freeze import setup, Executable

   build_exe_options = {"packages": ["numpy"]}

   setup(
        name = "Assignment4_5PythonExe",
        version = "0.1",
        description = "Sort Methods",
        options = {"build_exe": build_exe_options},
        executables = [Executable("Assignment4_5.py")]
        )


问:
Criteria Query unable to fetch Data
I've a hbm file for my database view with all the columns as composite key

```<code>    <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false">
    <class name="com.sample.dataobject.MyView"
        table="MY_VIEW" >
        <composite-id>
            <key-property name="code" type="string">
                <column name="CODE" length="2" />
            </key-property>
            <key-property name="Id" type="string">
                <column name="ID" length="14" />
            </key-property>
            <key-property name="Desc" type="string">
                <column name="DESC" length="256" />
            </key-property>
            <key-property name="TypeCode" type="string">
                <column name="TYPE_CODE" length="2" />
            </key-property>
        </composite-id>
    </class>
</hibernate-mapping>
</code>```

In the above view, the column DESC can be a null value.

I've written a criteria query to fetch results based on CODE and ID

```<code>Criteria c = getSession().createCriteria(MyView.class);
    c.add(Restrictions.eq("code", 'US'));
    c.add(Restrictions.eq("Id", '12'));
    List<MyView> annuityServices= c.list();
</code>```

There are 2 rows in the View which satisfies these conditions, but the List which is returned is [null,null]

Also when i put a logger to check the query and value, it returns 2 rows but break at DESC column which is null

```<code>    2017-06-07 17:08:19 TRACE BasicExtractor:78 - extracted value ([CODE_1_390_0_] : [VARCHAR]) - [US]
2017-06-07 17:08:19 TRACE BasicExtractor:78 - extracted value ([ID_2_390_0_] : [VARCHAR]) - [12]
2017-06-07 17:08:19 TRACE BasicExtractor:68 - extracted value ([DESC_9_390_0_] : [VARCHAR]) - [null]
2017-06-07 17:08:19 TRACE BasicExtractor:78 - extracted value ([CODE_1_390_0_] : [VARCHAR]) - [US]
2017-06-07 17:08:19 TRACE BasicExtractor:78 - extracted value ([ID_2_390_0_] : [VARCHAR]) - [12]
2017-06-07 17:08:19 TRACE BasicExtractor:68 - extracted value ([DESC_9_390_0_] : [VARCHAR]) - [null]
</code>```

Is there something wrong, or criteria API breaks when a null value is encountered?

Thanks

答:
In the above view, the column DESC can be a null value.

According to Hibernate documentation, primary key have to be not null:

The values cannot be null. For composite ids, no part can be null.

Title: Criteria Query unable to fetch Data

Body:
I've a hbm file for my database view with all the columns as composite key

    <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false">
    <class name="com.sample.dataobject.MyView"
        table="MY_VIEW" >
        <composite-id>
            <key-property name="code" type="string">
                <column name="CODE" length="2" />
            </key-property>
            <key-property name="Id" type="string">
                <column name="ID" length="14" />
            </key-property>
            <key-property name="Desc" type="string">
                <column name="DESC" length="256" />
            </key-property>
            <key-property name="TypeCode" type="string">
                <column name="TYPE_CODE" length="2" />
            </key-property>
        </composite-id>
    </class>
</hibernate-mapping>

In the above view, the column DESC can be a null value.

I've written a criteria query to fetch results based on CODE and ID

Criteria c = getSession().createCriteria(MyView.class);
    c.add(Restrictions.eq("code", 'US'));
    c.add(Restrictions.eq("Id", '12'));
    List<MyView> annuityServices= c.list();

There are 2 rows in the View which satisfies these conditions, but the List which is returned is [null,null]

Also when i put a logger to check the query and value, it returns 2 rows but break at DESC column which is null

    2017-06-07 17:08:19 TRACE BasicExtractor:78 - extracted value ([CODE_1_390_0_] : [VARCHAR]) - [US]
2017-06-07 17:08:19 TRACE BasicExtractor:78 - extracted value ([ID_2_390_0_] : [VARCHAR]) - [12]
2017-06-07 17:08:19 TRACE BasicExtractor:68 - extracted value ([DESC_9_390_0_] : [VARCHAR]) - [null]
2017-06-07 17:08:19 TRACE BasicExtractor:78 - extracted value ([CODE_1_390_0_] : [VARCHAR]) - [US]
2017-06-07 17:08:19 TRACE BasicExtractor:78 - extracted value ([ID_2_390_0_] : [VARCHAR]) - [12]
2017-06-07 17:08:19 TRACE BasicExtractor:68 - extracted value ([DESC_9_390_0_] : [VARCHAR]) - [null]

Is there something wrong, or criteria API breaks when a null value is encountered?

Thanks


问:
Div moving only once
I'm trying to make a simple application via Intel XDK. I made this button but it moves down only once after loading the page / application. I would be very grateful if somebody would advise me. Thanks in advance.

Code:

function buttonClick() {
    //alert('Thanks for using our app!!!');
    document.getElementById('button').style.boxShadow = "none";
    document.getElementById('button').style.top += "10px";
    setTimeout(function(){
      document.getElementById('button').style.top = "-10px";
        document.getElementById('button').style.boxShadow = "0px 5px 10px #3a926d";
        }, 500);
    }

function onLoad() {
    intel.xdk.device.setRotateOrientation("portrait");
}

document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);
function onDeviceReady(){
    // set orientation

    intel.xdk.device.setRotateOrientation('portrait');
//    intel.xdk.device.setRotateOrientation('any');

    intel.xdk.device.hideSplashScreen();
} ```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#button {
    background-color: #29c786;
    padding: 10px;
    width: 55%;
    height: 30px;
    line-height: 30px;
    text-align: center;
    margin-top: 0;
    color: white;
    position:absolute; /*it can be fixed too*/
    left:0; right:0;
    top:0; bottom:0;
    margin:auto;
    box-shadow: 0px 5px 10px #3a926d;
    border-radius: 5px;
}

footer {
    font-size: 8;
    position: absolute;
    bottom: 5px;
    left: 5px;
}</code>```

OPEN GALLERY

VERSION 0.1; © Tomas Hobza 2017```

答:
There's no need for JavaScript for this type of task.

Here is a CSS solution:

CSS

#button {
  background-color: #29c786;
  padding: 10px;
  width: 55%;
  height: 30px;
  line-height: 30px;
  text-align: center;
  margin-top: 0;
  color: white;
  position:absolute;
  left:0; right:0;
  top:0; bottom:0;
  margin:auto;
  box-shadow: 0px 5px 10px #3a926d;
  border-radius: 5px;
  transition: all 0.5s;
  font-family: Arial, Helvetica, sans-serif;
}

#button:active {
  transform: translateY(10px);
  box-shadow: none;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="button"><b>OPEN GALLERY</b></div></code>```

JSFiddle

Title: Div moving only once

Body:
I'm trying to make a simple application via Intel XDK. I made this button but it moves down only once after loading the page / application. I would be very grateful if somebody would advise me. Thanks in advance.

Code:

function buttonClick() {
    //alert('Thanks for using our app!!!');
    document.getElementById('button').style.boxShadow = "none";
    document.getElementById('button').style.top += "10px";
    setTimeout(function(){
      document.getElementById('button').style.top = "-10px";
        document.getElementById('button').style.boxShadow = "0px 5px 10px #3a926d";
        }, 500);
    }

function onLoad() {
    intel.xdk.device.setRotateOrientation("portrait");
}

document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);
function onDeviceReady(){
    // set orientation

    intel.xdk.device.setRotateOrientation('portrait');
//    intel.xdk.device.setRotateOrientation('any');

    intel.xdk.device.hideSplashScreen();
}

#button {
    background-color: #29c786;
    padding: 10px;
    width: 55%;
    height: 30px;
    line-height: 30px;
    text-align: center;
    margin-top: 0;
    color: white;
    position:absolute; /*it can be fixed too*/
    left:0; right:0;
    top:0; bottom:0;
    margin:auto;
    box-shadow: 0px 5px 10px #3a926d;
    border-radius: 5px;
}

footer {
    font-size: 8;
    position: absolute;
    bottom: 5px;
    left: 5px;
}

OPEN GALLERY

VERSION 0.1; © Tomas Hobza 2017

Body:
There's no need for JavaScript for this type of task.

Here is a CSS solution:

CSS

#button {
  background-color: #29c786;
  padding: 10px;
  width: 55%;
  height: 30px;
  line-height: 30px;
  text-align: center;
  margin-top: 0;
  color: white;
  position:absolute;
  left:0; right:0;
  top:0; bottom:0;
  margin:auto;
  box-shadow: 0px 5px 10px #3a926d;
  border-radius: 5px;
  transition: all 0.5s;
  font-family: Arial, Helvetica, sans-serif;
}

#button:active {
  transform: translateY(10px);
  box-shadow: none;
}

<div id="button"><b>OPEN GALLERY</b></div>

JSFiddle


问:
Double dot product of two tensors
I have two tensors: A is a second order tensor and B is a fourth order tensor. I know that when computing the double dot product (:) of two tensors, the rank of the resulting tensor will be decreased by two, so in my example the result should be a second order tensor.

However, when I write this code in MATLAB, it gives the following error:

Matrix dimensions must agree.

How can I solve this problem?

答:
It's very unfortunate, but MATLAB has not implemented an inner product of tensors in their standard library to my knowledge. To produce a scalar version of the inner product, you need to either inefficiently iterate through each entry like:

```<code>function C = double_dot(A,B)
    for i=1:1:3
        for j=1:1:3
            C = C + A(i,j)*B(i,j);
        end
    end
</code>```

Or you can run a slight modification of Eitan's vectorized code (above). His code produces a vector. The inner product of two tensors should be a scalar. So you need to sum across the final array that his code produces.

```<code>function C = double_dot(A, B)
    assert(~isvector(A) && ~isvector(B))
    idx = max(0, ndims(A) - 1);
    B_t = permute(B, circshift(1:ndims(A) + ndims(B), [0, idx - 1]));
    C = sum(squeeze(sum(squeeze(sum(bsxfun(@times, A, B_t), idx)), idx)));
</code>```

Eitan's code is an implementation of the dot function in matlab (see https://www.mathworks.com/help/matlab/ref/dot.html). Note the section on the dot product of matricies. Instead you should more simply use:

```<code>function C = double_dot(A,B)
    C = sum(dot(A,B));
</code>```

Title: Double dot product of two tensors

Body:
It's very unfortunate, but MATLAB has not implemented an inner product of tensors in their standard library to my knowledge. To produce a scalar version of the inner product, you need to either inefficiently iterate through each entry like:

function C = double_dot(A,B)
    for i=1:1:3
        for j=1:1:3
            C = C + A(i,j)*B(i,j);
        end
    end

Or you can run a slight modification of Eitan's vectorized code (above). His code produces a vector. The inner product of two tensors should be a scalar. So you need to sum across the final array that his code produces.

function C = double_dot(A, B)
    assert(~isvector(A) && ~isvector(B))
    idx = max(0, ndims(A) - 1);
    B_t = permute(B, circshift(1:ndims(A) + ndims(B), [0, idx - 1]));
    C = sum(squeeze(sum(squeeze(sum(bsxfun(@times, A, B_t), idx)), idx)));

Eitan's code is an implementation of the dot function in matlab (see https://www.mathworks.com/help/matlab/ref/dot.html). Note the section on the dot product of matricies. Instead you should more simply use:

function C = double_dot(A,B)
    C = sum(dot(A,B));


问:
Not able to view more than 4 dimensions in QlikSense
I have included Sankey JS as external plugin to Qlik sense. I have added total of 5 dimensions and 1 measure to my chart. But when I view the chart, I'm able to see only 4 dimensions and the last dimension replaces the previous dimensions. For Ex:

Dim1, Dim2, Dim3, Dim4 - It looks fine when I include only 4 dimensions.

Dim1, Dim2, Dim3, Dim5 - If I add 5th dimension to the chart.

The problem is when I view QDataPages[0] size object, I'm able to see only values for 4 dimensions under the qMatrix object. How do I crease the size or see more dimensions. Your help is really appreciated.

```requirejs.config({
  shim : {
    "extensions/SenseSankey/sankeymore" : {
      "deps" : ["extensions/SenseSankey/d3.min"]
    }
  }
});
//define(["jquery", "text!./style.css","extensions/SenseSankey/sankeymore"], function($, cssContent) {
define(["jquery", "text!./style.css","core.utils/theme","extensions/SenseSankey/md5.min","extensions/SenseSankey/sankeymore"], function($, cssContent, Theme, md5) {
    'use strict';
    $( "

答:
Just an assumption: Did you change this code from qWidth=4 to qWidth=5?

```<code>qInitialDataFetch: [{
                    qWidth: 5,
                    qHeight: 2000
                }
</code>```

If this is the case, then remove the extension from your sheet, refresh the browser and re-add the extension again!

Body:
I have included Sankey JS as external plugin to Qlik sense. I have added total of 5 dimensions and 1 measure to my chart. But when I view the chart, I'm able to see only 4 dimensions and the last dimension replaces the previous dimensions. For Ex:

Dim1, Dim2, Dim3, Dim4 - It looks fine when I include only 4 dimensions.

Dim1, Dim2, Dim3, Dim5 - If I add 5th dimension to the chart.

The problem is when I view QDataPages[0] size object, I'm able to see only values for 4 dimensions under the qMatrix object. How do I crease the size or see more dimensions. Your help is really appreciated.

requirejs.config({
  shim : {
    "extensions/SenseSankey/sankeymore" : {
      "deps" : ["extensions/SenseSankey/d3.min"]
    }
  }
});
//define(["jquery", "text!./style.css","extensions/SenseSankey/sankeymore"], function($, cssContent) {
define(["jquery", "text!./style.css","core.utils/theme","extensions/SenseSankey/md5.min","extensions/SenseSankey/sankeymore"], function($, cssContent, Theme, md5) {
    'use strict';
    $( "

Body:
Just an assumption: Did you change this code from qWidth=4 to qWidth=5?

qInitialDataFetch: [{
                    qWidth: 5,
                    qHeight: 2000
                }

If this is the case, then remove the extension from your sheet, refresh the browser and re-add the extension again!


问:
Open and write an xml file in C#
I have a xml file which I want to open and write in. The xml file has this structure:

```<code> <?xml version="1.0" encoding="UTF-8"?>
   <polygons>
     <polygon name="polygon-1">
         <point>
            <x>38,241885</x>
            <y>-5,965407</y>
         </point>
          <point>
            <x>38,242251</x>
            <y>-5,965423</y>
         </point>
    </polygon>
    <polygon name="polygon-2">
        .
        .
    </polygon>
  </polygons>
</code>```

I want to add new polygons into my xml, so I have to read it and then add a polygon at the last position. ¿How can I do this?

答:
you can generate C#(polygon/point/etc) code using xsd.exe by xml file(step by step instruction: https://msdn.microsoft.com/en-us/library/5s2x1sy7(v=vs.110).aspx).

add objects to list of poligons and serialize structure using XmlSerializer
https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(v=vs.110).aspx

Title: Open and write an xml file in C#

Body:
I have a xml file which I want to open and write in. The xml file has this structure:

 <?xml version="1.0" encoding="UTF-8"?>
   <polygons>
     <polygon name="polygon-1">
         <point>
            <x>38,241885</x>
            <y>-5,965407</y>
         </point>
          <point>
            <x>38,242251</x>
            <y>-5,965423</y>
         </point>
    </polygon>
    <polygon name="polygon-2">
        .
        .
    </polygon>
  </polygons>

I want to add new polygons into my xml, so I have to read it and then add a polygon at the last position. ¿How can I do this?


问:
Why doesn't haddock generate HTML for some modules in base?
There are some modules in the base haddock that don't have documentation links. For example, GHC/Show.hs has haddock comments, but there is no documentation for the GHC.Show module on Hackage. Why not? Is this a bug?

答:
This is apparently intentional. It a result of this line in GHC/Show.hs:

```<code>{-# OPTIONS_HADDOCK hide #-}
</code>```

Relevant excerpts from the haddock documentation:

Certain attributes may be specified for each module which affects the way that Haddock generates documentation for that module. Attributes are specified in a comma-separated list in an {-# OPTIONS_HADDOCK ... #-} pragma at the top of the module, either before or after the module description.

[...]

The following attributes are currently understood by Haddock:

hide

Omit this module from the generated documentation, but nevertheless propagate definitions and documentation from within this module to modules that re-export those definitions.

[...]

Body:
This is apparently intentional. It a result of this line in GHC/Show.hs:

{-# OPTIONS_HADDOCK hide #-}

Relevant excerpts from the haddock documentation:

Certain attributes may be specified for each module which affects the way that Haddock generates documentation for that module. Attributes are specified in a comma-separated list in an {-# OPTIONS_HADDOCK ... #-} pragma at the top of the module, either before or after the module description.

[...]

The following attributes are currently understood by Haddock:

hide

Omit this module from the generated documentation, but nevertheless propagate definitions and documentation from within this module to modules that re-export those definitions.

[...]


问:
How to resolve class conflict in import statements
Im trying to write a program that will read an xml file and print to itext.

However, I getting a class conflict in import statements. I dont know how to resolve this issue.

```<code>import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import org.w3c.dom.NodeList;
import org.w3c.dom.*;

import com.itextpdf.text.Annotation;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfAction;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
</code>```

The "Document" and "Element" classes between dom4j and itext are conflicting.

Does anyone know a workaround? Is there any eclipse magic I can do?

答: In such cases , you should use fully qualified class name for one of the conflicting classes while using it.</p>

Body:
Im trying to write a program that will read an xml file and print to itext.

However, I getting a class conflict in import statements. I dont know how to resolve this issue.

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import org.w3c.dom.NodeList;
import org.w3c.dom.*;

import com.itextpdf.text.Annotation;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfAction;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

The "Document" and "Element" classes between dom4j and itext are conflicting.

Does anyone know a workaround? Is there any eclipse magic I can do?


问:
From SQL server, extract a list of Users containing the list of all their bought application (mapping table)
Let Users be a database containing typical users data (name, email...) with an ID as primary key.

Let Applications be a database storing a list of applications (name, developer...) with an ID as primary key.

Let UsersApps be the mapping table between the two, using the primary key. UsersApps thus stores rows of ..., {102, user1_Id, appA_Id}, {103, userN_ID, appB_Id}, {104, user1_Id, appC_Id}, ...
And so on.

I want to retrieve a list of users data {name, email, List<Application> boughtApps}

I am struggling to find a LINQ request to do that and I am trying to do it in two steps, get a big table and then build each user's list of applications.

```<code>            var q1 = from user in _dbContext.Users
                     join appUti in _dbContext.AppUsers on user.Id equals appUti.UsersId
                     join app in _dbContext.Applications on appUti.ApplicationId equals app.Id
                     orderby user.Id
                     select new UserDataWithApp { Id = user.Id, Name = user.Name, firstName= user.FirstName, Email = user.Email, App = app };
</code>```

Then parse q1.toList() to build my required results list.

```<code>       var qRes = q1.ToList();
       int i = 0;
       int j = 0;
        while (i<qRes.Count())
        {
                listUsersWithApps[j] = qRes[i];
                while (qRes[i].Id == listUsersWithApps[j].Id) // llist is ordered !!
                {
                    listUsersWithApps[j].Apps.Add(qRes[i].Apps[0]);
                    i++;
                }
                j++;
     }
</code>```

Isn't there a better way ?

答:
You can use navigation properties to allow the following:

```<code>var userApps = context.Users.Select(u => new UserWithApp(u.Name, u.Email, u.Applications))
</code>```

Just add to following to User:

```<code>public virtual ICollection<Application> Applications { get; set; }
</code>```

and to Application:

```<code>public virtual ICollection<Users> Users { get; set; }
</code>```

So you can "navigate" between your entities and write to following query (just adapt your ordering and what user data to be seleted):

```<code>var userApps = from user in context.Users
               select new UserDataWithApp { ..., BoughtApps = user.Applications }
</code>```

See here for an example: http://www.entityframeworktutorial.net/code-first/configure-many-to-many-relationship-in-code-first.aspx

or another interesting blog: https://lostechies.com/jimmybogard/2014/03/12/avoid-many-to-many-mappings-in-orms/

Body:
Let Users be a database containing typical users data (name, email...) with an ID as primary key.

Let Applications be a database storing a list of applications (name, developer...) with an ID as primary key.

Let UsersApps be the mapping table between the two, using the primary key. UsersApps thus stores rows of ..., {102, user1_Id, appA_Id}, {103, userN_ID, appB_Id}, {104, user1_Id, appC_Id}, ...
And so on.

I want to retrieve a list of users data {name, email, List<Application> boughtApps}

I am struggling to find a LINQ request to do that and I am trying to do it in two steps, get a big table and then build each user's list of applications.

            var q1 = from user in _dbContext.Users
                     join appUti in _dbContext.AppUsers on user.Id equals appUti.UsersId
                     join app in _dbContext.Applications on appUti.ApplicationId equals app.Id
                     orderby user.Id
                     select new UserDataWithApp { Id = user.Id, Name = user.Name, firstName= user.FirstName, Email = user.Email, App = app };

Then parse q1.toList() to build my required results list.

       var qRes = q1.ToList();
       int i = 0;
       int j = 0;
        while (i<qRes.Count())
        {
                listUsersWithApps[j] = qRes[i];
                while (qRes[i].Id == listUsersWithApps[j].Id) // llist is ordered !!
                {
                    listUsersWithApps[j].Apps.Add(qRes[i].Apps[0]);
                    i++;
                }
                j++;
     }

Isn't there a better way ?

Body:
You can use navigation properties to allow the following:

var userApps = context.Users.Select(u => new UserWithApp(u.Name, u.Email, u.Applications))

Just add to following to User:

public virtual ICollection<Application> Applications { get; set; }

and to Application:

public virtual ICollection<Users> Users { get; set; }

So you can "navigate" between your entities and write to following query (just adapt your ordering and what user data to be seleted):

var userApps = from user in context.Users
               select new UserDataWithApp { ..., BoughtApps = user.Applications }

See here for an example: http://www.entityframeworktutorial.net/code-first/configure-many-to-many-relationship-in-code-first.aspx

or another interesting blog: https://lostechies.com/jimmybogard/2014/03/12/avoid-many-to-many-mappings-in-orms/


问:
Copy array items into another array
I have a JavaScript array dataArray which I want to push into a new array newArray. Except I don't want newArray[0] to be dataArray. I want to push in all the items into the new array:

```<code>var newArray = [];

newArray.pushValues(dataArray1);
newArray.pushValues(dataArray2);
// ...
</code>```

or even better:

```<code>var newArray = new Array (
   dataArray1.values(),
   dataArray2.values(),
   // ... where values() (or something equivalent) would push the individual values into the array, rather than the array itself
);
</code>```

So now the new array contains all the values of the individual data arrays.  Is there some shorthand like pushValues available so I don't have to iterate over each individual dataArray, adding the items one by one?

答:
We have two array a and b. the code what did here is array a value is pushed into array b.</p>

```<code>let a = [2, 4, 6, 8, 9, 15]

function transform(a) {
    let b = ['4', '16', '64']
    a.forEach(function(e) {
        b.push(e.toString());
    });
    return b;
}

transform(a)

[ '4', '16', '64', '2', '4', '6', '8', '9', '15' ]
</code>```

Title: Copy array items into another array

Body:
I have a JavaScript array dataArray which I want to push into a new array newArray. Except I don't want newArray[0] to be dataArray. I want to push in all the items into the new array:

var newArray = [];

newArray.pushValues(dataArray1);
newArray.pushValues(dataArray2);
// ...

or even better:

var newArray = new Array (
   dataArray1.values(),
   dataArray2.values(),
   // ... where values() (or something equivalent) would push the individual values into the array, rather than the array itself
);

So now the new array contains all the values of the individual data arrays.  Is there some shorthand like pushValues available so I don't have to iterate over each individual dataArray, adding the items one by one?

Body:
We have two array a and b. the code what did here is array a value is pushed into array b.

let a = [2, 4, 6, 8, 9, 15]

function transform(a) {
    let b = ['4', '16', '64']
    a.forEach(function(e) {
        b.push(e.toString());
    });
    return b;
}

transform(a)

[ '4', '16', '64', '2', '4', '6', '8', '9', '15' ]


问:
How to Dict.get a case insensitive key?
I'd like to grab the Total-Records key of a response.headers HTTP response.

Problem is that in some browser it is as returned by the server Total-Records but in some other, it is in lower case.

I'd like to get the value of the Total-Records header regardless of its case.
How would you do that?

答:
In this situation I think I might go (uses elm-community/list-extra):</p>

```<code>getFirstCaseInsensitive : String -> Dict String v -> Maybe v
getFirstCaseInsensitive key dict =
    let
        key_ =
            String.toLower key
    in
        dict
            |> Dict.toList
            |> List.Extra.find
                ((==) key_ << String.toLower << Tuple.first)
            |> Maybe.map Tuple.second
</code>```

Title: How to Dict.get a case insensitive key?

Body:
In this situation I think I might go (uses elm-community/list-extra):

getFirstCaseInsensitive : String -> Dict String v -> Maybe v
getFirstCaseInsensitive key dict =
    let
        key_ =
            String.toLower key
    in
        dict
            |> Dict.toList
            |> List.Extra.find
                ((==) key_ << String.toLower << Tuple.first)
            |> Maybe.map Tuple.second


问:
Does this code contain use-after-free?
```<code>int f2(char* x, int f) {
    int i=0;
    free(x);
    if(f) {
        printf("%s", x);
        return 1;
    }
    return 0;
}

int main(int argc, char argv) {
    char* x = malloc(10);
    return f2(x, argc);
}
</code>```

Is passing freed pointer to printf considered use-after free?

答:
You'll get undefined behaviour (google that term) several times:

in f2 you are dereferencing x once it has been freed, because printfing x with the %s format specifier will dereference x, or in other words it will access the memory pointed by x, and that memory will have undetermined content after calling free.

even if you remove the free(x), you still get undefined behaviour, because then you are printfing x, while x is pointing to valid but non initialized memory.

Title: Does this code contain use-after-free?

Body:
int f2(char* x, int f) {
    int i=0;
    free(x);
    if(f) {
        printf("%s", x);
        return 1;
    }
    return 0;
}

int main(int argc, char argv) {
    char* x = malloc(10);
    return f2(x, argc);
}

Is passing freed pointer to printf considered use-after free?


问:
jQuery onChange event handler firing function twice
This is the table http://jsfiddle.net/djochw6L/1/
The event is supposed to fire when I enter value in the item column

```<code>$(document).on('change', '.item', function() {
    var ite = $(this).closest('tr');
    getdetails(ite);
})//event

function getdetails(dat){
    var itemName = $(dat).find('.item').val();
    alert (itemName);
};
</code>```

The event handler works correct for the first row. But from the second row onwards it fires twice. Why is this?

答:
The reason why it's firing twice is because your on change element fires for every class with the name item. If you look through your code you can see that on top of giving every table column the class item, you are also passing the item class to each row that is added. So the event fires twice, once for the row and once for the item column.

The code that's giving you the problem is

```<code>prot.attr("class", id + " item")
</code>```

Try to fix your problem by not passing the item class to the table rows, instead of doing all kinds of hacky stuff to the event listener.

You could build your code to something along the lines of

```<code>prot.attr("class", "item-" + id)
</code>```

Body:
This is the table http://jsfiddle.net/djochw6L/1/
The event is supposed to fire when I enter value in the item column

$(document).on('change', '.item', function() {
    var ite = $(this).closest('tr');
    getdetails(ite);
})//event

function getdetails(dat){
    var itemName = $(dat).find('.item').val();
    alert (itemName);
};

The event handler works correct for the first row. But from the second row onwards it fires twice. Why is this?

Body:
The reason why it's firing twice is because your on change element fires for every class with the name item. If you look through your code you can see that on top of giving every table column the class item, you are also passing the item class to each row that is added. So the event fires twice, once for the row and once for the item column.

The code that's giving you the problem is

prot.attr("class", id + " item")

Try to fix your problem by not passing the item class to the table rows, instead of doing all kinds of hacky stuff to the event listener.

You could build your code to something along the lines of

prot.attr("class", "item-" + id)


问:
Ionic trigger modal open function with ion-searchbar focus - click not working
I have an ion-searchbar that, when clicked, opens a modal. However, currently the click process is actually taking two clicks, one to focus, one to open the modal. I have tried to add the click to the ion-toolbar it is contained in, and have tried to disable the ion-searchbar with [disabled]="true", but the disabled functionality isn't available to the ion-searchbar. How can I trigger the new modal to open without having to double click, and in such a way that the focus doesn't happen on the original searchbar?

HTML

```<code><ion-header>
  <ion-toolbar >
    <ion-searchbar (click)="openSearchModal()"></ion-searchbar>
  </ion-toolbar>
</ion-header>
</code>```

JS

```<code>  openSearchModal() {
    let myModal = this.modalCtrl.create(SearchmodalPage);
    myModal.present();
  }
</code>```

答:
Add this function inside the class of your .ts file (best practice is before constructor):

ionViewDidLoad(){
    document.getElementsByClassName('searchbar-input')[0].setAttribute("onFocus", "openSearchModal()");
}
```

<h2>Explanation</h2>

<p>The <code>ion-searchbar</code> ionic element creates multiple child elements, one of which is of course an <code>input</code> element which has a class <code>searchbarElement</code>.</p>

<p>We first ask to get all those elements with this class name. This returns an array of such elements, in the first position of which, at index = 0, resides the <code><input></code> field of which the functionality we want to change.</p>

<p>We then programmatically set an <code>onFocus</code> attribute that is called when an element gains focus (e.g. when clicked). This in essence makes it look like the following:</p>

```<input class="searchbar-input" onFocus="openSearchModal()">
```

So in the end, when the user clicks on the search box, the modal is called.

We then wrap all of this inside an ionViewDidLoad() which is a lifecycle hook ionic provides that we can use to run code right after the view has loaded.

Body:
I have an ion-searchbar that, when clicked, opens a modal. However, currently the click process is actually taking two clicks, one to focus, one to open the modal. I have tried to add the click to the ion-toolbar it is contained in, and have tried to disable the ion-searchbar with [disabled]="true", but the disabled functionality isn't available to the ion-searchbar. How can I trigger the new modal to open without having to double click, and in such a way that the focus doesn't happen on the original searchbar?

HTML

<ion-header>
  <ion-toolbar >
    <ion-searchbar (click)="openSearchModal()"></ion-searchbar>
  </ion-toolbar>
</ion-header>

JS

  openSearchModal() {
    let myModal = this.modalCtrl.create(SearchmodalPage);
    myModal.present();
  }

Body:
Add this function inside the class of your .ts file (best practice is before constructor):

ionViewDidLoad(){
    document.getElementsByClassName('searchbar-input')[0].setAttribute("onFocus", "openSearchModal()");
}

Explanation

The ion-searchbar ionic element creates multiple child elements, one of which is of course an input element which has a class searchbarElement.

We first ask to get all those elements with this class name. This returns an array of such elements, in the first position of which, at index = 0, resides the <input> field of which the functionality we want to change.

We then programmatically set an onFocus attribute that is called when an element gains focus (e.g. when clicked). This in essence makes it look like the following:

<input class="searchbar-input" onFocus="openSearchModal()">

So in the end, when the user clicks on the search box, the modal is called.

We then wrap all of this inside an ionViewDidLoad() which is a lifecycle hook ionic provides that we can use to run code right after the view has loaded.


答:
You need to specify the package when using them in your code.
Otherwise there is an ambiguity as Document could refer to either org.dom4j.Document or com.itextpdf.text.Document and Element could refer to org.dom4j.Element or com.itextpdf.text.Element.

Title: How to resolve class conflict in import statements