问:
How to debug an error when I create a string in login method?

03-30 23:49:56.536 15105-15105/? D/dalvikvm: Late-enabling CheckJNI
  03-30 23:49:56.560 15105-15111/? E/jdwp: Failed writing handshake
  bytes: Broken pipe (-1 of 14) 03-30 23:49:56.560 15105-15111/?
  D/dalvikvm: Debugger has detached; object registry had 0 entries 03-30
  23:49:56.600 15105-15105/? I/dalvikvm: Could not find method
  android.view.Window$Callback.onProvideKeyboardShortcuts, referenced
  from method
  android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
  03-30 23:49:56.600 15105-15105/? W/dalvikvm: VFY: unable to resolve
  interface method 21845:
  Landroid/view/Window$Callback;.onProvideKeyboardShortcuts
  (Ljava/util/List;Landroid/view/Menu;I)V 03-30 23:49:56.600
  15105-15105/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 03-30
  23:49:56.604 15105-15105/? W/dalvikvm: VFY: unable to find class
  referenced in signature (Landroid/view/SearchEvent;) 03-30
  23:49:56.604 15105-15105/? I/dalvikvm: Could not find method
  android.view.Window$Callback.onSearchRequested, referenced from method
  android.support.v7.view.WindowCallbackWrapper.onSearchRequested 03-30
  23:49:56.604 15105-15105/? W/dalvikvm: VFY: unable to resolve
  interface method 21847:
  Landroid/view/Window$Callback;.onSearchRequested
  (Landroid/view/SearchEvent;)Z 03-30 23:49:56.604 15105-15105/?
  D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 03-30 23:49:56.604
  15105-15105/? I/dalvikvm: Could not find method
  android.view.Window$Callback.onWindowStartingActionMode, referenced
  from method
  android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
  03-30 23:49:56.604 15105-15105/? W/dalvikvm: VFY: unable to resolve
  interface method 21851:
  Landroid/view/Window$Callback;.onWindowStartingActionMode
  (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 03-30
  23:49:56.604 15105-15105/? D/dalvikvm: VFY: replacing opcode 0x72 at
  0x0002 03-30 23:49:56.604 15105-15105/? I/dalvikvm: Could not find
  method android.content.res.TypedArray.getChangingConfigurations,
  referenced from method
  android.support.v7.widget.TintTypedArray.getChangingConfigurations
  03-30 23:49:56.604 15105-15105/? W/dalvikvm: VFY: unable to resolve
  virtual method 502:
  Landroid/content/res/TypedArray;.getChangingConfigurations ()I 03-30
  23:49:56.604 15105-15105/? D/dalvikvm: VFY: replacing opcode 0x6e at
  0x0002 03-30 23:49:56.604 15105-15105/? I/dalvikvm: Could not find
  method android.content.res.TypedArray.getType, referenced from method
  android.support.v7.widget.TintTypedArray.getType 03-30 23:49:56.604
  15105-15105/? W/dalvikvm: VFY: unable to resolve virtual method 524:
  Landroid/content/res/TypedArray;.getType (I)I 03-30 23:49:56.604
  15105-15105/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008 03-30
  23:49:56.636 15105-15105/? I/dalvikvm: Could not find method
  android.widget.FrameLayout.startActionModeForChild, referenced from
  method
  android.support.v7.widget.ActionBarContainer.startActionModeForChild
  03-30 23:49:56.636 15105-15105/? W/dalvikvm: VFY: unable to resolve
  virtual method 22329:
  Landroid/widget/FrameLayout;.startActionModeForChild
  (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
  03-30 23:49:56.640 15105-15105/? D/dalvikvm: VFY: replacing opcode
  0x6f at 0x0002 03-30 23:49:56.640 15105-15105/? I/dalvikvm: Could not
  find method android.content.Context.getColorStateList, referenced from
  method
  android.support.v7.content.res.AppCompatResources.getColorStateList
  03-30 23:49:56.640 15105-15105/? W/dalvikvm: VFY: unable to resolve
  virtual method 315: Landroid/content/Context;.getColorStateList
  (I)Landroid/content/res/ColorStateList; 03-30 23:49:56.640
  15105-15105/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006 03-30
  23:49:56.652 15105-15105/? I/dalvikvm: Could not find method
  android.content.res.Resources.getDrawable, referenced from method
  android.support.v7.widget.ResourcesWrapper.getDrawable 03-30
  23:49:56.652 15105-15105/? W/dalvikvm: VFY: unable to resolve virtual
  method 465: Landroid/content/res/Resources;.getDrawable
  (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
  03-30 23:49:56.652 15105-15105/? D/dalvikvm: VFY: replacing opcode
  0x6e at 0x0002 03-30 23:49:56.652 15105-15105/? I/dalvikvm: Could not
  find method android.content.res.Resources.getDrawableForDensity,
  referenced from method
  android.support.v7.widget.ResourcesWrapper.getDrawableForDensity 03-30
  23:49:56.652 15105-15105/? W/dalvikvm: VFY: unable to resolve virtual
  method 467: Landroid/content/res/Resources;.getDrawableForDensity
  (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
  03-30 23:49:56.652 15105-15105/? D/dalvikvm: VFY: replacing opcode
  0x6e at 0x0002 03-30 23:49:56.660 15105-15105/? E/dalvikvm: Could not
  find class 'android.graphics.drawable.RippleDrawable', referenced from
  method
  android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
  03-30 23:49:56.660 15105-15105/? W/dalvikvm: VFY: unable to resolve
  instanceof 150 (Landroid/graphics/drawable/RippleDrawable;) in
  Landroid/support/v7/widget/AppCompatImageHelper; 03-30 23:49:56.660
  15105-15105/? D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c 03-30
  23:49:56.680 15105-15108/? D/dalvikvm: GC_CONCURRENT freed 234K, 22%
  free 2639K/3364K, paused 1ms+2ms, total 9ms 03-30 23:49:56.692
  15105-15105/? D/dalvikvm: GC_FOR_ALLOC freed 31K, 21% free
  2676K/3364K, paused 3ms, total 3ms 03-30 23:49:56.692 15105-15105/?
  I/dalvikvm-heap: Grow heap (frag case) to 3.506MB for 435468-byte
  allocation 03-30 23:49:56.692 15105-15114/? D/dalvikvm: GC_FOR_ALLOC
  freed 1K, 19% free 3100K/3792K, paused 3ms, total 3ms 03-30
  23:49:56.700 15105-15108/? D/dalvikvm: GC_CONCURRENT freed 3K, 19%
  free 3097K/3792K, paused 0ms+0ms, total 6ms 03-30 23:49:56.700
  15105-15105/? D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 5ms 03-30
  23:49:56.700 15105-15105/? I/dalvikvm-heap: Grow heap (frag case) to
  3.821MB for 333408-byte allocation 03-30 23:49:56.704 15105-15114/? D/dalvikvm: GC_FOR_ALLOC freed <1K, 17% free 3422K/4120K, paused 4ms,
  total 4ms 03-30 23:49:56.748 15105-15105/? D/libEGL: loaded
  /system/lib/egl/libEGL_genymotion.so

```<code>                                       [ 03-30 23:49:56.748 15105:15105 D/         ]
                                       HostConnection::get() New Host Connection established 0xb85b25b0, tid 15105

                                       [ 03-30 23:49:56.752    62:   62 D/         ]
                                       Socket deconnection 03-30 23:49:56.756 15105-15105/? D/libEGL: loaded
</code>```

/system/lib/egl/libGLESv1_CM_genymotion.so 03-30 23:49:56.756
  15105-15105/? D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so
  03-30 23:49:56.804 15105-15105/? W/EGL_genymotion: eglSurfaceAttrib
  not implemented 03-30 23:49:56.804 15105-15105/? E/OpenGLRenderer:
  Getting MAX_TEXTURE_SIZE from GradienCache 03-30 23:49:56.812
  15105-15105/? E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from
  Caches::initConstraints() 03-30 23:49:56.812 15105-15105/?
  D/OpenGLRenderer: Enabling debug mode 0 03-30 23:50:19.456
  15105-15105/com.example.samsungvy277.myapp E/InputEventSender:
  Exception dispatching finished signal. 03-30 23:50:19.456
  15105-15105/com.example.samsungvy277.myapp E/MessageQueue-JNI:
  Exception in MessageQueue callback: handleReceiveCallback 03-30
  23:50:19.468 15105-15105/com.example.samsungvy277.myapp D/dalvikvm:
  GC_FOR_ALLOC freed 806K, 30% free 3127K/4428K, paused 5ms, total 5ms
  03-30 23:50:19.468 15105-15105/com.example.samsungvy277.myapp
  E/MessageQueue-JNI: java.lang.IllegalStateException: Could not execute
  method for android:onClick
                                                                                at
  android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                                at android.view.View.performClick(View.java:4240)
                                                                                at android.view.View.onKeyUp(View.java:7928)
                                                                                at android.widget.TextView.onKeyUp(TextView.java:5606)
                                                                                at android.view.KeyEvent.dispatch(KeyEvent.java:2647)
                                                                                at android.view.View.dispatchKeyEvent(View.java:7343)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1933)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1408)
                                                                                at android.app.Activity.dispatchKeyEvent(Activity.java:2384)
                                                                                at
  android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:541)
                                                                                at
  android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
                                                                                at
  android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1860)
                                                                                at
  android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3791)
                                                                                at
  android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3774)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3516)
                                                                                at
  android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3666)
                                                                                at
  android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:1982)
                                                                                at
  android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1698)
                                                                                at
  android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1689)
                                                                                at
  android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1959)
                                                                                at
  android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
                                                                                at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                                at android.os.MessageQueue.next(MessageQueue.java:132)
                                                                                at android.os.Looper.loop(Looper.java:124)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5103)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at an 03-30 23:50:19.468 15105-15105/com.example.samsungvy277.myapp
  D/AndroidRuntime: Shutting down VM 03-30 23:50:19.472
  15105-15105/com.example.samsungvy277.myapp W/dalvikvm: threadid=1:
  thread exiting with uncaught exception (group=0xa4c2e648) 03-30
  23:50:19.480 15105-15105/com.example.samsungvy277.myapp
  E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                java.lang.IllegalStateException: Could not execute method for
  android:onClick
                                                                                at
  android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                                at android.view.View.performClick(View.java:4240)
                                                                                at android.view.View.onKeyUp(View.java:7928)
                                                                                at android.widget.TextView.onKeyUp(TextView.java:5606)
                                                                                at android.view.KeyEvent.dispatch(KeyEvent.java:2647)
                                                                                at android.view.View.dispatchKeyEvent(View.java:7343)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1933)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1408)
                                                                                at android.app.Activity.dispatchKeyEvent(Activity.java:2384)
                                                                                at
  android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:541)
                                                                                at
  android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
                                                                                at
  android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1860)
                                                                                at
  android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3791)
                                                                                at
  android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3774)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3516)
                                                                                at
  android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3666)
                                                                                at
  android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:1982)
                                                                                at
  android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1698)
                                                                                at
  android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1689)
                                                                                at
  android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1959)
                                                                                at
  android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
                                                                                at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                                at android.os.MessageQueue.next(MessageQueue.java:132)
                                                                                at android.os.Looper.loop(Looper.java:124)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5103)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Met 03-30 23:50:22.504
  15105-15105/? I/Process: Sending signal. PID: 15105 SIG: 9

答: Use findViewById after setting your setContentView(R.layout.activity_main)</p>

Body:
03-30 23:49:56.536 15105-15105/? D/dalvikvm: Late-enabling CheckJNI
  03-30 23:49:56.560 15105-15111/? E/jdwp: Failed writing handshake
  bytes: Broken pipe (-1 of 14) 03-30 23:49:56.560 15105-15111/?
  D/dalvikvm: Debugger has detached; object registry had 0 entries 03-30
  23:49:56.600 15105-15105/? I/dalvikvm: Could not find method
  android.view.Window$Callback.onProvideKeyboardShortcuts, referenced
  from method
  android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
  03-30 23:49:56.600 15105-15105/? W/dalvikvm: VFY: unable to resolve
  interface method 21845:
  Landroid/view/Window$Callback;.onProvideKeyboardShortcuts
  (Ljava/util/List;Landroid/view/Menu;I)V 03-30 23:49:56.600
  15105-15105/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 03-30
  23:49:56.604 15105-15105/? W/dalvikvm: VFY: unable to find class
  referenced in signature (Landroid/view/SearchEvent;) 03-30
  23:49:56.604 15105-15105/? I/dalvikvm: Could not find method
  android.view.Window$Callback.onSearchRequested, referenced from method
  android.support.v7.view.WindowCallbackWrapper.onSearchRequested 03-30
  23:49:56.604 15105-15105/? W/dalvikvm: VFY: unable to resolve
  interface method 21847:
  Landroid/view/Window$Callback;.onSearchRequested
  (Landroid/view/SearchEvent;)Z 03-30 23:49:56.604 15105-15105/?
  D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 03-30 23:49:56.604
  15105-15105/? I/dalvikvm: Could not find method
  android.view.Window$Callback.onWindowStartingActionMode, referenced
  from method
  android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
  03-30 23:49:56.604 15105-15105/? W/dalvikvm: VFY: unable to resolve
  interface method 21851:
  Landroid/view/Window$Callback;.onWindowStartingActionMode
  (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 03-30
  23:49:56.604 15105-15105/? D/dalvikvm: VFY: replacing opcode 0x72 at
  0x0002 03-30 23:49:56.604 15105-15105/? I/dalvikvm: Could not find
  method android.content.res.TypedArray.getChangingConfigurations,
  referenced from method
  android.support.v7.widget.TintTypedArray.getChangingConfigurations
  03-30 23:49:56.604 15105-15105/? W/dalvikvm: VFY: unable to resolve
  virtual method 502:
  Landroid/content/res/TypedArray;.getChangingConfigurations ()I 03-30
  23:49:56.604 15105-15105/? D/dalvikvm: VFY: replacing opcode 0x6e at
  0x0002 03-30 23:49:56.604 15105-15105/? I/dalvikvm: Could not find
  method android.content.res.TypedArray.getType, referenced from method
  android.support.v7.widget.TintTypedArray.getType 03-30 23:49:56.604
  15105-15105/? W/dalvikvm: VFY: unable to resolve virtual method 524:
  Landroid/content/res/TypedArray;.getType (I)I 03-30 23:49:56.604
  15105-15105/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008 03-30
  23:49:56.636 15105-15105/? I/dalvikvm: Could not find method
  android.widget.FrameLayout.startActionModeForChild, referenced from
  method
  android.support.v7.widget.ActionBarContainer.startActionModeForChild
  03-30 23:49:56.636 15105-15105/? W/dalvikvm: VFY: unable to resolve
  virtual method 22329:
  Landroid/widget/FrameLayout;.startActionModeForChild
  (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
  03-30 23:49:56.640 15105-15105/? D/dalvikvm: VFY: replacing opcode
  0x6f at 0x0002 03-30 23:49:56.640 15105-15105/? I/dalvikvm: Could not
  find method android.content.Context.getColorStateList, referenced from
  method
  android.support.v7.content.res.AppCompatResources.getColorStateList
  03-30 23:49:56.640 15105-15105/? W/dalvikvm: VFY: unable to resolve
  virtual method 315: Landroid/content/Context;.getColorStateList
  (I)Landroid/content/res/ColorStateList; 03-30 23:49:56.640
  15105-15105/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006 03-30
  23:49:56.652 15105-15105/? I/dalvikvm: Could not find method
  android.content.res.Resources.getDrawable, referenced from method
  android.support.v7.widget.ResourcesWrapper.getDrawable 03-30
  23:49:56.652 15105-15105/? W/dalvikvm: VFY: unable to resolve virtual
  method 465: Landroid/content/res/Resources;.getDrawable
  (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
  03-30 23:49:56.652 15105-15105/? D/dalvikvm: VFY: replacing opcode
  0x6e at 0x0002 03-30 23:49:56.652 15105-15105/? I/dalvikvm: Could not
  find method android.content.res.Resources.getDrawableForDensity,
  referenced from method
  android.support.v7.widget.ResourcesWrapper.getDrawableForDensity 03-30
  23:49:56.652 15105-15105/? W/dalvikvm: VFY: unable to resolve virtual
  method 467: Landroid/content/res/Resources;.getDrawableForDensity
  (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
  03-30 23:49:56.652 15105-15105/? D/dalvikvm: VFY: replacing opcode
  0x6e at 0x0002 03-30 23:49:56.660 15105-15105/? E/dalvikvm: Could not
  find class 'android.graphics.drawable.RippleDrawable', referenced from
  method
  android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
  03-30 23:49:56.660 15105-15105/? W/dalvikvm: VFY: unable to resolve
  instanceof 150 (Landroid/graphics/drawable/RippleDrawable;) in
  Landroid/support/v7/widget/AppCompatImageHelper; 03-30 23:49:56.660
  15105-15105/? D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c 03-30
  23:49:56.680 15105-15108/? D/dalvikvm: GC_CONCURRENT freed 234K, 22%
  free 2639K/3364K, paused 1ms+2ms, total 9ms 03-30 23:49:56.692
  15105-15105/? D/dalvikvm: GC_FOR_ALLOC freed 31K, 21% free
  2676K/3364K, paused 3ms, total 3ms 03-30 23:49:56.692 15105-15105/?
  I/dalvikvm-heap: Grow heap (frag case) to 3.506MB for 435468-byte
  allocation 03-30 23:49:56.692 15105-15114/? D/dalvikvm: GC_FOR_ALLOC
  freed 1K, 19% free 3100K/3792K, paused 3ms, total 3ms 03-30
  23:49:56.700 15105-15108/? D/dalvikvm: GC_CONCURRENT freed 3K, 19%
  free 3097K/3792K, paused 0ms+0ms, total 6ms 03-30 23:49:56.700
  15105-15105/? D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 5ms 03-30
  23:49:56.700 15105-15105/? I/dalvikvm-heap: Grow heap (frag case) to
  3.821MB for 333408-byte allocation 03-30 23:49:56.704 15105-15114/? D/dalvikvm: GC_FOR_ALLOC freed <1K, 17% free 3422K/4120K, paused 4ms,
  total 4ms 03-30 23:49:56.748 15105-15105/? D/libEGL: loaded
  /system/lib/egl/libEGL_genymotion.so

                                       [ 03-30 23:49:56.748 15105:15105 D/         ]
                                       HostConnection::get() New Host Connection established 0xb85b25b0, tid 15105

                                       [ 03-30 23:49:56.752    62:   62 D/         ]
                                       Socket deconnection 03-30 23:49:56.756 15105-15105/? D/libEGL: loaded

/system/lib/egl/libGLESv1_CM_genymotion.so 03-30 23:49:56.756
  15105-15105/? D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so
  03-30 23:49:56.804 15105-15105/? W/EGL_genymotion: eglSurfaceAttrib
  not implemented 03-30 23:49:56.804 15105-15105/? E/OpenGLRenderer:
  Getting MAX_TEXTURE_SIZE from GradienCache 03-30 23:49:56.812
  15105-15105/? E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from
  Caches::initConstraints() 03-30 23:49:56.812 15105-15105/?
  D/OpenGLRenderer: Enabling debug mode 0 03-30 23:50:19.456
  15105-15105/com.example.samsungvy277.myapp E/InputEventSender:
  Exception dispatching finished signal. 03-30 23:50:19.456
  15105-15105/com.example.samsungvy277.myapp E/MessageQueue-JNI:
  Exception in MessageQueue callback: handleReceiveCallback 03-30
  23:50:19.468 15105-15105/com.example.samsungvy277.myapp D/dalvikvm:
  GC_FOR_ALLOC freed 806K, 30% free 3127K/4428K, paused 5ms, total 5ms
  03-30 23:50:19.468 15105-15105/com.example.samsungvy277.myapp
  E/MessageQueue-JNI: java.lang.IllegalStateException: Could not execute
  method for android:onClick
                                                                                at
  android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                                at android.view.View.performClick(View.java:4240)
                                                                                at android.view.View.onKeyUp(View.java:7928)
                                                                                at android.widget.TextView.onKeyUp(TextView.java:5606)
                                                                                at android.view.KeyEvent.dispatch(KeyEvent.java:2647)
                                                                                at android.view.View.dispatchKeyEvent(View.java:7343)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1933)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1408)
                                                                                at android.app.Activity.dispatchKeyEvent(Activity.java:2384)
                                                                                at
  android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:541)
                                                                                at
  android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
                                                                                at
  android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1860)
                                                                                at
  android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3791)
                                                                                at
  android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3774)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3516)
                                                                                at
  android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3666)
                                                                                at
  android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:1982)
                                                                                at
  android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1698)
                                                                                at
  android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1689)
                                                                                at
  android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1959)
                                                                                at
  android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
                                                                                at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                                at android.os.MessageQueue.next(MessageQueue.java:132)
                                                                                at android.os.Looper.loop(Looper.java:124)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5103)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at an 03-30 23:50:19.468 15105-15105/com.example.samsungvy277.myapp
  D/AndroidRuntime: Shutting down VM 03-30 23:50:19.472
  15105-15105/com.example.samsungvy277.myapp W/dalvikvm: threadid=1:
  thread exiting with uncaught exception (group=0xa4c2e648) 03-30
  23:50:19.480 15105-15105/com.example.samsungvy277.myapp
  E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                java.lang.IllegalStateException: Could not execute method for
  android:onClick
                                                                                at
  android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
                                                                                at android.view.View.performClick(View.java:4240)
                                                                                at android.view.View.onKeyUp(View.java:7928)
                                                                                at android.widget.TextView.onKeyUp(TextView.java:5606)
                                                                                at android.view.KeyEvent.dispatch(KeyEvent.java:2647)
                                                                                at android.view.View.dispatchKeyEvent(View.java:7343)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1393)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1933)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1408)
                                                                                at android.app.Activity.dispatchKeyEvent(Activity.java:2384)
                                                                                at
  android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:541)
                                                                                at
  android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
                                                                                at
  android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319)
                                                                                at
  com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1860)
                                                                                at
  android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3791)
                                                                                at
  android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3774)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at
  android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at
  android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at
  android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at
  android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3516)
                                                                                at
  android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3666)
                                                                                at
  android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:1982)
                                                                                at
  android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1698)
                                                                                at
  android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1689)
                                                                                at
  android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1959)
                                                                                at
  android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
                                                                                at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                                at android.os.MessageQueue.next(MessageQueue.java:132)
                                                                                at android.os.Looper.loop(Looper.java:124)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5103)
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                at
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                                at dalvik.system.NativeStart.main(Native Method)
                                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                at java.lang.reflect.Method.invoke(Met 03-30 23:50:22.504
  15105-15105/? I/Process: Sending signal. PID: 15105 SIG: 9


来源: stackexchange

问:
How to make ajax call using jquery each for each input type files in a form
I am having a simple form with one input for single file and another input for multiple files how can I make ajax call looping file by file and along with other form data each time?

```<code><form id = "uploadForm" name = "uploadForm" enctype="multipart/form-data">
    <label for="uploadFile">Upload Your File</label>
    <input type="file" name="uploadFile" id="uploadFile">
    <input type="file" name="attachment" id="attachments" multiple />

    <input type="text" name="attachmentId" value="1236">
    <input type="text" name="attachmentName" >
    <input type="text" name="JobId" value="xyz" >
    <input type="text" name="fileCategory" value="abc">
</code>```

Right now I am doing whole ajax Form submit like below:

```<code>$('#'+formId).ajaxForm({
    url:FileUploadUrl,
    headers: { "X-Requested-With":"XMLHttpRequest" },
    contentType: 'application/json',
    dataType:'json',
    success : function(data){
},
</code>```

But I want to do it for one file at a time, Please help thanks in advance.

答:
Not certain what purpose is for calling $.ajax() for each File object,  though you can use $.when(), Function.prototype.apply(), $.map(), .map() to perform request for each File at input type="file" FileList at .files property

```<code>var n = 0;
var requests = $.when.apply($, $.map($("#uploadForm :file"), function(input) {
  return $.when.apply($, [].slice.call(input.files).map(function(file, index) {
             return $.ajax({url, data:new FormData("file-" + n++, file)})
           })
         )
}))
.then(function(results) {
     console.log(results)
}, function handleErr(err) {
     console.log(err)
})
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I am having a simple form with one input for single file and another input for multiple files how can I make ajax call looping file by file and along with other form data each time?

<form id = "uploadForm" name = "uploadForm" enctype="multipart/form-data">
    Upload Your File
    <input type="file" name="uploadFile" id="uploadFile">
    <input type="file" name="attachment" id="attachments" multiple />

    <input type="text" name="attachmentId" value="1236">
    <input type="text" name="attachmentName" >
    <input type="text" name="JobId" value="xyz" >
    <input type="text" name="fileCategory" value="abc">

Right now I am doing whole ajax Form submit like below:

$('#'+formId).ajaxForm({
    url:FileUploadUrl,
    headers: { "X-Requested-With":"XMLHttpRequest" },
    contentType: 'application/json',
    dataType:'json',
    success : function(data){
},

But I want to do it for one file at a time, Please help thanks in advance.

Body:
Not certain what purpose is for calling $.ajax() for each File object,  though you can use $.when(), Function.prototype.apply(), $.map(), .map() to perform request for each File at input type="file" FileList at .files property

var n = 0;
var requests = $.when.apply($, $.map($("#uploadForm :file"), function(input) {
  return $.when.apply($, [].slice.call(input.files).map(function(file, index) {
             return $.ajax({url, data:new FormData("file-" + n++, file)})
           })
         )
}))
.then(function(results) {
     console.log(results)
}, function handleErr(err) {
     console.log(err)
})


问:
(C) When calling function, store multiple values in array
So, when calling a function I wish to put two values in, then those two values to be saved in an array in the function argument.

i.e

```<code>function(1,2); (calling the function)

void function(int x[2]); (declaration of function)
</code>```

with x[0] and x[1] being the two arguments when calling the function (i.e the 1 and 2).

Any help would be appreciated.

答:
function(1,2);
the function call will look for definition of type (int , int).

void function(int x[2]);
this function argument is of an array type. so it is not possible to call the function by function(1,2);

Body:
So, when calling a function I wish to put two values in, then those two values to be saved in an array in the function argument.

i.e

function(1,2); (calling the function)

void function(int x[2]); (declaration of function)

with x[0] and x[1] being the two arguments when calling the function (i.e the 1 and 2).

Any help would be appreciated.


问:
form input with autonumber yii2 something wrong
I've tried to make form input with autonumber using extensions mdmsoft/yii2-autonumber. And the result in my browser this bellow.

And this my code form in view.

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\Donatur */
/* @var $form yii\widgets\ActiveForm */
?>

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'kode_donatur')->textInput(['readonly' => true, 'value' => 'kode_donatur']) ?>

    <?= $form->field($model, 'nama_donatur')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'alamat')->textArea(['rows' => 6]) ?>

    <?= $form->field($model, 'telepon')->textInput(['maxlength' => true]) ?>

        <?= Html::submitButton($model->isNewRecord ? 'Simpan' : 'Ubah', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        <?php
  echo "&nbsp";
  echo "&nbsp";
  echo Html::a('Keluar', ['index'],['class'=>'btn btn-primary']);
  ?>

    <?php ActiveForm::end(); ?>

```
</div>
</div>
</p>

<p>And I want autonumber display in textfield "Kode donatur". An example can be seen in the image below.
<img src="https://i.stack.imgur.com/4ucjc.jpg" alt="enter image description here"></p>

<p>Code in controller</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-html lang-html prettyprint-override"><code><?php

namespace app\controllers;

use Yii;
use app\models\Donatur;
use app\models\SearchDonatur;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * DonaturController implements the CRUD actions for Donatur model.
 */
class DonaturController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all Donatur models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new SearchDonatur();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single Donatur model.
     * @param string $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    /**
     * Creates a new Donatur model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new Donatur();
        if (Yii::$app->request->post()) {
            $model->load(Yii::$app->request->post());
            if ($model->save()) {
                \Yii::$app->session->setFlash('success', 'Data berhasil disimpan!');
            } else {
                Yii::$app->session->setFlash('error', 'Data gagal disimpan!');
            }
            return $this->redirect(['index']);
            return $this->refresh();

        }
        else {
            return $this->render('create', ['model' => $model]);
        }
    }

    /**
     * Updates an existing Donatur model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = Donatur::findOne($id);

        if (Yii::$app->request->post()) {
            $model->load(Yii::$app->request->post());
            if ($model->save()) {
                Yii::$app->session->setFlash('success', 'Data berhasil diupdate!');
            } else {
                Yii::$app->session->setFlash('error', 'Data gagal diupdate!');
            }
            return $this->redirect(['index']);
            return $this->refresh();
        }
        else {
            return $this->render('update', ['model' => $model]);
        }
    }

    /**
     * Deletes an existing Donatur model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $id
     * @return mixed
     */
    public function actionDelete($kode_donatur)
    {
        $model = Donatur::findOne($kode_donatur);
        $model->delete();
        Yii::$app->session->setFlash('delete', 'Data berhasil dihapus!');
        return $this->redirect(['index']);
    }

    /**
     * Finds the Donatur model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $id
     * @return Donatur the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Donatur::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }

}</code>```

Code in model

<?php

namespace app\models;

use yii\db\ActiveRecord;

class Donatur extends ActiveRecord
{
 public static function tableName()
 {
  return 'donatur';
 }

 public function rules()
 {
  return [
      [['nama_donatur', 'alamat', 'telepon'], 'required'],
      [['kode_donatur', 'nama_donatur', 'alamat'], 'string'],
      [['telepon'], 'integer'],
      ];
 }

 public function behaviors()
    {
    return [
        [
            'class' => 'mdm\autonumber\Behavior',
            'attribute' => 'kode_donatur', // required
            //'group' => $this->id_branch, // optional
            'value' => 'D'.'?' , // format auto number. '?' will be replaced with generated number
            'digit' => 4 // optional, default to null.
        ],
    ];
    }

}```

答:
Your behaviours() function is not in the model it should be in your controller.Like this,</p>

```<code> public function behaviors()
{
    return [
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'delete' => ['POST'],
            ],
        ],
        [
          'class' => 'mdm\autonumber\Behavior',
        'attribute' => 'kode_donatur', // required
        //'group' => $this->id_branch, // optional
        'value' => 'D'.'?' , // format auto number. '?' will be replaced with generated number
        'digit' => 4 // optional, default to null.
        ],
    ];
}
</code>```

Body:
I've tried to make form input with autonumber using extensions mdmsoft/yii2-autonumber. And the result in my browser this bellow.

And this my code form in view.

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\Donatur */
/* @var $form yii\widgets\ActiveForm */
?>

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'kode_donatur')->textInput(['readonly' => true, 'value' => 'kode_donatur']) ?>

    <?= $form->field($model, 'nama_donatur')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'alamat')->textArea(['rows' => 6]) ?>

    <?= $form->field($model, 'telepon')->textInput(['maxlength' => true]) ?>

        <?= Html::submitButton($model->isNewRecord ? 'Simpan' : 'Ubah', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        <?php
  echo "&nbsp";
  echo "&nbsp";
  echo Html::a('Keluar', ['index'],['class'=>'btn btn-primary']);
  ?>

    <?php ActiveForm::end(); ?>

And I want autonumber display in textfield "Kode donatur". An example can be seen in the image below.

Code in controller

<?php

namespace app\controllers;

use Yii;
use app\models\Donatur;
use app\models\SearchDonatur;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * DonaturController implements the CRUD actions for Donatur model.
 */
class DonaturController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all Donatur models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new SearchDonatur();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single Donatur model.
     * @param string $id
     * @return mixed
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    /**
     * Creates a new Donatur model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new Donatur();
        if (Yii::$app->request->post()) {
            $model->load(Yii::$app->request->post());
            if ($model->save()) {
                \Yii::$app->session->setFlash('success', 'Data berhasil disimpan!');
            } else {
                Yii::$app->session->setFlash('error', 'Data gagal disimpan!');
            }
            return $this->redirect(['index']);
            return $this->refresh();

        }
        else {
            return $this->render('create', ['model' => $model]);
        }
    }

    /**
     * Updates an existing Donatur model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param string $id
     * @return mixed
     */
    public function actionUpdate($id)
    {
        $model = Donatur::findOne($id);

        if (Yii::$app->request->post()) {
            $model->load(Yii::$app->request->post());
            if ($model->save()) {
                Yii::$app->session->setFlash('success', 'Data berhasil diupdate!');
            } else {
                Yii::$app->session->setFlash('error', 'Data gagal diupdate!');
            }
            return $this->redirect(['index']);
            return $this->refresh();
        }
        else {
            return $this->render('update', ['model' => $model]);
        }
    }

    /**
     * Deletes an existing Donatur model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param string $id
     * @return mixed
     */
    public function actionDelete($kode_donatur)
    {
        $model = Donatur::findOne($kode_donatur);
        $model->delete();
        Yii::$app->session->setFlash('delete', 'Data berhasil dihapus!');
        return $this->redirect(['index']);
    }

    /**
     * Finds the Donatur model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $id
     * @return Donatur the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Donatur::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }

}

Code in model

<?php

namespace app\models;

use yii\db\ActiveRecord;

class Donatur extends ActiveRecord
{
 public static function tableName()
 {
  return 'donatur';
 }

 public function rules()
 {
  return [
      [['nama_donatur', 'alamat', 'telepon'], 'required'],
      [['kode_donatur', 'nama_donatur', 'alamat'], 'string'],
      [['telepon'], 'integer'],
      ];
 }

 public function behaviors()
    {
    return [
        [
            'class' => 'mdm\autonumber\Behavior',
            'attribute' => 'kode_donatur', // required
            //'group' => $this->id_branch, // optional
            'value' => 'D'.'?' , // format auto number. '?' will be replaced with generated number
            'digit' => 4 // optional, default to null.
        ],
    ];
    }

}

Body:
Your behaviours() function is not in the model it should be in your controller.Like this,

 public function behaviors()
{
    return [
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'delete' => ['POST'],
            ],
        ],
        [
          'class' => 'mdm\autonumber\Behavior',
        'attribute' => 'kode_donatur', // required
        //'group' => $this->id_branch, // optional
        'value' => 'D'.'?' , // format auto number. '?' will be replaced with generated number
        'digit' => 4 // optional, default to null.
        ],
    ];
}


问:
Increment and Decrement through array using modulus operator or Js
I was able to figure out the how to increment through my array reading through another question. Now I cant seem to figure out how to deincrement since my value is being set back to 0. I am trying to avoid a loop.

The order I am looking to acheive is:

Increment ---- "/", "/about", "/list" <-- list is the end. Decrement is just rewinding. Decrement is just going a 1 step back each time.

```<code>let i = 0;
let stuff =["/", "about","list"];

next() {
    this.props.dispatch(increaseCounter())
    i = (i+1)%stuff.length;
  }
  prev() {
    this.props.dispatch(decreaseCounter())
    i = (i-1)%stuff.length; <------This gets wonky once I reach the end of my array.
  }
</code>```

答:
If you want next() to increment i between 0 and 2 and prev() to decrement between 2 and 0 you can use the following:

```<code>next() {
    this.props.dispatch(increaseCounter());
    i = Math.min(i + 1, stuff.length - 1);
}

prev() {
    this.props.dispatch(decreaseCounter());
    i = Math.max(i - 1, 0);
}
</code>```

Body:
I was able to figure out the how to increment through my array reading through another question. Now I cant seem to figure out how to deincrement since my value is being set back to 0. I am trying to avoid a loop.

The order I am looking to acheive is:

Increment ---- "/", "/about", "/list" <-- list is the end. Decrement is just rewinding. Decrement is just going a 1 step back each time.

let i = 0;
let stuff =["/", "about","list"];

next() {
    this.props.dispatch(increaseCounter())
    i = (i+1)%stuff.length;
  }
  prev() {
    this.props.dispatch(decreaseCounter())
    i = (i-1)%stuff.length; <------This gets wonky once I reach the end of my array.
  }

Body:
If you want next() to increment i between 0 and 2 and prev() to decrement between 2 and 0 you can use the following:

next() {
    this.props.dispatch(increaseCounter());
    i = Math.min(i + 1, stuff.length - 1);
}

prev() {
    this.props.dispatch(decreaseCounter());
    i = Math.max(i - 1, 0);
}


问:
Creating an excel macro to format data in an XLS file
Im working on creating a Macro to clean up some raw data outputted into an XLS by some software and make it more readable and filterable etc..

The data is formatted in the following manner (there are about 25k lines formatted identically to this:
Example of data format

and I would like it to look something like
this: (Manually made as an example)

I was hoping the wizards of stackoverflow would be able to help me!

Thanks.

答:
Assuming your data is in the 1st sheet, create a 2nd sheet and then the following should work:</p>

```<code>Option Explicit

Sub cleanUpData()
  Dim sht2 As Worksheet: Set sht2 = Sheets(2)

  Dim r As Integer, r2 As Integer: r2 = 2
  With Sheets(1):
    sht2.Range("A1:J1").Value = .Range("A1:J1").Value
    For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).row Step 5:
      sht2.Range("A" & r2 & ":J" & r2).Value = .Range("A" & r & ":J" & r).Value
      sht2.Cells(r2, "J").Value = .Cells(r + 1, "A").Value & " " & .Cells(r + 1, "B").Value
      r2 = r2 + 1
    Next
  End With

  sht2.Columns("A:J").EntireColumn.AutoFit

End Sub
</code>```

Body:
Assuming your data is in the 1st sheet, create a 2nd sheet and then the following should work:

Option Explicit

Sub cleanUpData()
  Dim sht2 As Worksheet: Set sht2 = Sheets(2)

  Dim r As Integer, r2 As Integer: r2 = 2
  With Sheets(1):
    sht2.Range("A1:J1").Value = .Range("A1:J1").Value
    For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).row Step 5:
      sht2.Range("A" & r2 & ":J" & r2).Value = .Range("A" & r & ":J" & r).Value
      sht2.Cells(r2, "J").Value = .Cells(r + 1, "A").Value & " " & .Cells(r + 1, "B").Value
      r2 = r2 + 1
    Next
  End With

  sht2.Columns("A:J").EntireColumn.AutoFit

End Sub


问:
Dynamically allocating an array of objects to a pointer using new: "potentially uninitialized pointer"
The following function must allocate memory for a database of objects, assigning a pointer to the array of objects.

A pointer will then loop down the array using pointer arithmetic and initialize each object to the correct values, following user input.

Here is the code that doesn't work:

```<code>//**********************************************************************
//*                        Get Database Records                        *
//**********************************************************************
record* get_records_database(int quantity)
{
   record *p_database; // Pointer to the records database
   record *p_record;   // Pointer to each object in the database
   int    index = 1; // Number of objects in the database

   // Allocate a database of object records
   try
   {
      p_database = new record[quantity];
   }
   catch (bad_alloc xa)
   {
      fatal_error(ALLOC_ERR, "get_records_database",
                             "object records database");
   }

   // Loop processing object records until the database is filled
   // --- //

   // Test:
   p_database->set_amount(400);
   p_database->get_amount();

   return p_database;
}
</code>```

The problem I face is fixing the following compiler error in VisualStudio: error C4703: potentially uninitialized local pointer variable 'p_employee_database' used.

This is a project; using new, try, catch, and pointers, is required; the structure of the function is required (not all written at this point); the return value of a pointer to a class is required. My teacher is extremely strict in following his requirements precisely.

Any help to the resolution of this error is greatly appreciated. Thank you ;)

答:
There are at least two issues with your code here:

```<code>   try
   {
      p_employee_database = new employee_bonus_record[employee_quantity];
   }
   catch (bad_alloc xa)
   {
      fatal_error(EMPLOYEE_ALLOC_ERR, "get_employee_records_database",
                                      "employee bonus records database");
   }
   //.. rest of code, assuming p_employee_database is ok.
</code>```

If the exception is thrown, the p_employee_database is uninitialized, however you failed to return from the function.  Instead your logic proceeds using p_employee_database as if nothing is wrong, thus the compiler warning.

Even as you stated, fatal_error calls exit(), the compiler doesn't see this.  It only looks at that block of code and gives the warning.  If you want to suppress the warning, you can return nullptr.

```<code>   try
   {
      p_employee_database = new employee_bonus_record[employee_quantity];
   }
   catch (const bad_alloc& xa)
   {
      fatal_error(EMPLOYEE_ALLOC_ERR, "get_employee_records_database",
                                      "employee bonus records database");
      return nullptr;
   }
</code>```

The second thing wrong with the code is that you should catch the std::bad_alloc by const reference, not by value.  See this article.

Body:
The following function must allocate memory for a database of objects, assigning a pointer to the array of objects.

A pointer will then loop down the array using pointer arithmetic and initialize each object to the correct values, following user input.

Here is the code that doesn't work:

//**********************************************************************
//*                        Get Database Records                        *
//**********************************************************************
record* get_records_database(int quantity)
{
   record *p_database; // Pointer to the records database
   record *p_record;   // Pointer to each object in the database
   int    index = 1; // Number of objects in the database

   // Allocate a database of object records
   try
   {
      p_database = new record[quantity];
   }
   catch (bad_alloc xa)
   {
      fatal_error(ALLOC_ERR, "get_records_database",
                             "object records database");
   }

   // Loop processing object records until the database is filled
   // --- //

   // Test:
   p_database->set_amount(400);
   p_database->get_amount();

   return p_database;
}

The problem I face is fixing the following compiler error in VisualStudio: error C4703: potentially uninitialized local pointer variable 'p_employee_database' used.

This is a project; using new, try, catch, and pointers, is required; the structure of the function is required (not all written at this point); the return value of a pointer to a class is required. My teacher is extremely strict in following his requirements precisely.

Any help to the resolution of this error is greatly appreciated. Thank you ;)

Body:
There are at least two issues with your code here:

   try
   {
      p_employee_database = new employee_bonus_record[employee_quantity];
   }
   catch (bad_alloc xa)
   {
      fatal_error(EMPLOYEE_ALLOC_ERR, "get_employee_records_database",
                                      "employee bonus records database");
   }
   //.. rest of code, assuming p_employee_database is ok.

If the exception is thrown, the p_employee_database is uninitialized, however you failed to return from the function.  Instead your logic proceeds using p_employee_database as if nothing is wrong, thus the compiler warning.

Even as you stated, fatal_error calls exit(), the compiler doesn't see this.  It only looks at that block of code and gives the warning.  If you want to suppress the warning, you can return nullptr.

   try
   {
      p_employee_database = new employee_bonus_record[employee_quantity];
   }
   catch (const bad_alloc& xa)
   {
      fatal_error(EMPLOYEE_ALLOC_ERR, "get_employee_records_database",
                                      "employee bonus records database");
      return nullptr;
   }

The second thing wrong with the code is that you should catch the std::bad_alloc by const reference, not by value.  See this article.


问:
How to use variable from a while (foreach) statement in a query?
I have this first query

```<code> <?php
       while($empsheetpanel=mysqli_fetch_array($resultempsheets)){

 ?>
</code>```

Under that I have placed this second query in order to get data from the first query

```<code> <?php
 $sql="SELECT * From my_table WHERE id="$empsheetpanel['employee_id']" ";
 $result=mysqli_query($db,$sql);
 ?>
<?php } ;?>
</code>```

I know this is improper and incorrect. What's the correct syntax to retrieve the $empsheetpanel['employee_id'] from the first query?

答:
You need to use . to concatenate strings:

```<code>$sql="SELECT * From my_table WHERE id=" . $empsheetpanel['employee_id'];
</code>```

or you can use string interpolation:

```<code>$sql="SELECT * From my_table WHERE id={$empsheetpanel['employee_id']}";
</code>```

But a better solution is not to do this as separate queries in a loop. Join this table with your original query.

So if your first query was:

```<code>SELECT * FROM my_other_table WHERE some conditions here
</code>```

you would join them together as:

```<code>SELECT *
FROM my_other_table
JOIN my_table ON my_table.id = my_other_table.employee_id
WHERE some conditions here
</code>```

Each row of this result will contain the combination of data from the two tables. If my_table might not have matching rows, you should use LEFT JOIN instead of JOIN.

Body:
I have this first query

 <?php
       while($empsheetpanel=mysqli_fetch_array($resultempsheets)){

 ?>

Under that I have placed this second query in order to get data from the first query

 <?php
 $sql="SELECT * From my_table WHERE id="$empsheetpanel['employee_id']" ";
 $result=mysqli_query($db,$sql);
 ?>
<?php } ;?>

I know this is improper and incorrect. What's the correct syntax to retrieve the $empsheetpanel['employee_id'] from the first query?

Body:
You need to use . to concatenate strings:

$sql="SELECT * From my_table WHERE id=" . $empsheetpanel['employee_id'];

or you can use string interpolation:

$sql="SELECT * From my_table WHERE id={$empsheetpanel['employee_id']}";

But a better solution is not to do this as separate queries in a loop. Join this table with your original query.

So if your first query was:

SELECT * FROM my_other_table WHERE some conditions here

you would join them together as:

SELECT *
FROM my_other_table
JOIN my_table ON my_table.id = my_other_table.employee_id
WHERE some conditions here

Each row of this result will contain the combination of data from the two tables. If my_table might not have matching rows, you should use LEFT JOIN instead of JOIN.


问:
Reversing elements in Arrays
```<code>public static void main(String[] args) {

    int[] HwArray = new int[10];
    for (int i = 0; i < HwArray.length; i++) {
        HwArray[i] = i;
        }

    int count = 0;
    for (int i = 0; i < HwArray.length; i++){
    HwArray[i] = (int) (100 + Math.random() * 100);

    System.out.print("HwArray[i]=" + HwArray[i]);
            }

        }

    {
        int[] reverse(int[] HwArray); {
            int[] reversed = new int[HwArray.length];
            for (int i=0; i<HwArray.length; i++) {
                reversed[i] = HwArray[HwArray.length - 1 - i];
            }
            return reverse;
        }
    }

}
</code>```

Sorry, I'm still learning. I'm trying to reverse the order of all the elements, but I keep receiving an error. Am I doing something wrong?

答:
There are many errors:

First of all, it should be return reversed instead of return reverse.

Then, you cannot define any method inside a method(here, method reverse is defined inside the main method)

Then, you can do one thing, remove the following two braces:
1: The opening brace just before int[] reverse(int[] HwArray)
2: The closing brace in the last line

Last, it should be int[] reverse(int[] HwArray) { instead of int[] reverse(int[] HwArray); {

Title: Reversing elements in Arrays

Body:
public static void main(String[] args) {

    int[] HwArray = new int[10];
    for (int i = 0; i < HwArray.length; i++) {
        HwArray[i] = i;
        }

    int count = 0;
    for (int i = 0; i < HwArray.length; i++){
    HwArray[i] = (int) (100 + Math.random() * 100);

    System.out.print("HwArray[i]=" + HwArray[i]);
            }

        }

    {
        int[] reverse(int[] HwArray); {
            int[] reversed = new int[HwArray.length];
            for (int i=0; i<HwArray.length; i++) {
                reversed[i] = HwArray[HwArray.length - 1 - i];
            }
            return reverse;
        }
    }

}

Sorry, I'm still learning. I'm trying to reverse the order of all the elements, but I keep receiving an error. Am I doing something wrong?


问:
What are coding conventions for using floating-point in Linux device drivers?
This is related to
this question.

I'm not an expert on Linux device drivers or kernel modules, but I've been reading "Linux Device Drivers" [O'Reilly] by Rubini & Corbet and a number of online sources, but I haven't been able to find anything on this specific issue yet.

When is a kernel or driver module allowed to use floating-point registers?

If so, who is responsible for saving and restoring their contents?

(Assume x86-64 architecture)

If I understand correctly, whenever a KM is running, it is using a hardware context (or hardware thread or register set -- whatever you want to call it) that has been preempted from some application thread.  If you write your KM in c, the compiler will correctly insure that the general-purpose registers are properly saved and restored (much as in an application), but that doesn't automatically happen with floating-point registers.  For that matter, a lot of KMs can't even assume that the processor has any floating-point capability.

Am I correct in guessing that a KM that wants to use floating-point has to carefully save and restore the floating-point state?  Are there standard kernel functions for doing this?

Are the coding conventions for this spelled out anywhere?
  Are they different for SMP-non SMP drivers?
 Are they different for older non-preemptive kernels and newer preemptive kernels?

答:
Short answer: Kernel code can use floating point if this use is surrounded by kernel_fpu_begin()/kernel_fpu_end(). These function handle saving and restoring the fpu context. Also, they call preempt_disable()/preempt_enable(), which means no sleeping, page faults etc. in the code between those functions. Google the function names for more information.

If I understand correctly, whenever a
  KM is running, it is using a hardware
  context (or hardware thread or
  register set -- whatever you want to
  call it) that has been preempted from
  some application thread.

No, a kernel module can run in user context as well (eg. when userspace calls syscalls on a device provided by the KM). It has, however, no relation to the float issue.

If you write your KM in c, the
  compiler will correctly insure that
  the general-purpose registers are
  properly saved and restored (much as
  in an application), but that doesn't
  automatically happen with
  floating-point registers.

That is not because of the compiler, but because of the kernel context-switching code.

OwnerDisplayName: Die in Sente

ContentLicense: CC BY-SA 2.5

LastEditorDisplayName: starblue

OwnerDisplayName: jpalecek


问:
Pass parameter to callback function of gadget.io.makeRequest
I would like to pass a parameter to the callback function of gadget.io.MakeRequest.
Is this at all possible?

```<code>function MyRequest(param){
...
gadget.io.makeRequest(url, callback, opt_params, param);
...
}

function callback(result,param)
{
    eval("param(result)");
}

if (a==1)
  MyRequest(mycbk1);
if (a==2)
  MyRequest(mycbk2);

function mycbk1(result){
  // handle results of makeRequest when a==1
}
function mycbk21(result){
 // handle results of makeRequest when a==1
}
</code>```

答:
One possibility is to wrap your callback function in an anonymous function, like so:

```<code>function MyRequest(param){
    ...
    gadget.io.makeRequest(
        url,
        function(result) { callback(result, param); },
        opt_params);
    ...
}
</code>```

When the gadget request finishes, the anonymous function will be called with result as the only argument. The anonymous function subsequently calls your callback function with both result and param as arguments.

Body:
I would like to pass a parameter to the callback function of gadget.io.MakeRequest.
Is this at all possible?

function MyRequest(param){
...
gadget.io.makeRequest(url, callback, opt_params, param);
...
}

function callback(result,param)
{
    eval("param(result)");
}

if (a==1)
  MyRequest(mycbk1);
if (a==2)
  MyRequest(mycbk2);

function mycbk1(result){
  // handle results of makeRequest when a==1
}
function mycbk21(result){
 // handle results of makeRequest when a==1
}

Body:
One possibility is to wrap your callback function in an anonymous function, like so:

function MyRequest(param){
    ...
    gadget.io.makeRequest(
        url,
        function(result) { callback(result, param); },
        opt_params);
    ...
}

When the gadget request finishes, the anonymous function will be called with result as the only argument. The anonymous function subsequently calls your callback function with both result and param as arguments.


答:
```<code>Comparator<Integer> comparator = new Comparator<Integer>() {
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
};

// option 1
Integer[] array = new Integer[] { 11, 44, 4, 3, 123 };
Arrays.sort(array, comparator);

// option 2
int[] array2 = new int[] {11, 44, 4, 3, 123};
List<Integer>list = Ints.asList(array2);
Collections.sort(list, comparator);
array2 = Ints.toArray(list);

// option 3
List<Integer> integersList = Ints.asList(arr);
Collections.sort(integersList, Collections.reverseOrder());
</code>```

Title: Reversing elements in Arrays


问:
(S)CSS architecture: alternative backgrounds styling
I'm using 'component' approach to CSS as in SMACSS / ITCSS, I'm still scratching my head about styling sections with alternative (dark) background.

e.g. Stripe has regular (dark text on white) and alternative (white text on dark) sections.

As I understand there are options assuming HTML:

```<code><section class="dark">
    <h2>Title</h2>
    <p>Text</p>
    <a href="#" class="btn">Action</a>
</section>
</code>```

Style in context of section, e.g.:

```<code>.dark h2, .dark p, .dark btn {
  color: white;
}
</code>```

But a) context styling is not recommended; b) where does one put the styles? (Harry Roberts argues that in component's file)

Create alternative-colored components with modifiers

And change the HTML, e.g.:

```<code>.title--alt-color {color: white;}
.text--alt-color {color: white; }
...
</code>```

But a) it doesn't work when you don't know which components will go in there; b) more work of managing HTML.

Maybe there is a better way to handle this?

答:
In a component based approach the ideal way to do this is to have a mapping ready between backgrounds and foreground colours in your style guide. It should be a one to one mapping that should apply to majority of your elements. Have CSS classes defined for the same.

Next have a wrapper container for all your components. Its purpose is to impart text colours to its wrapped components. So the approach is to have a background colour class for the section and then a foreground colour class for the contents that runs applies to wrapper but runs the style through all the contents.

Note: Specific colour overrides can always reside inside your components file for instance using a highlight on some text etc.

The library that is suggested in the comments does the exact same thing. There is a primary and secondary colour in the theme object. The primary applied to the section and secondary is passed on to the individual components as context. I suggest having it passed only to the components' wrapper.

A somewhat clever way to have classes defined is like

```<code>t-wrapper-[colorName]
</code>```

Now this can be generic and colorName can come in as a context to your wrapper based on the background color

Hope this helps. Let me know if this answers what you need or you would need supporting snippets for the same.

Body:
I'm using 'component' approach to CSS as in SMACSS / ITCSS, I'm still scratching my head about styling sections with alternative (dark) background.

e.g. Stripe has regular (dark text on white) and alternative (white text on dark) sections.

As I understand there are options assuming HTML:

Title

Text

    Action

Style in context of section, e.g.:

.dark h2, .dark p, .dark btn {
  color: white;
}

But a) context styling is not recommended; b) where does one put the styles? (Harry Roberts argues that in component's file)

Create alternative-colored components with modifiers

And change the HTML, e.g.:

.title--alt-color {color: white;}
.text--alt-color {color: white; }
...

But a) it doesn't work when you don't know which components will go in there; b) more work of managing HTML.

Maybe there is a better way to handle this?

Body:
In a component based approach the ideal way to do this is to have a mapping ready between backgrounds and foreground colours in your style guide. It should be a one to one mapping that should apply to majority of your elements. Have CSS classes defined for the same.

Next have a wrapper container for all your components. Its purpose is to impart text colours to its wrapped components. So the approach is to have a background colour class for the section and then a foreground colour class for the contents that runs applies to wrapper but runs the style through all the contents.

Note: Specific colour overrides can always reside inside your components file for instance using a highlight on some text etc.

The library that is suggested in the comments does the exact same thing. There is a primary and secondary colour in the theme object. The primary applied to the section and secondary is passed on to the individual components as context. I suggest having it passed only to the components' wrapper.

A somewhat clever way to have classes defined is like

t-wrapper-[colorName]

Now this can be generic and colorName can come in as a context to your wrapper based on the background color

Hope this helps. Let me know if this answers what you need or you would need supporting snippets for the same.


问:
(Python) Return value from if-statement does not get assigned to variable outside the if-statement
```<code>def my_diet(event, style):
    if event == 1:
        choice = raw_input("""What type of animal are you?
        A) Carnivore
        B) Herbivore
        C) Omnivore
        """)
        if choice == "A":
            style = "Carnivore"
            print style
        elif choice == "B":
            style = "Herbivore"
        elif choice == "C":
            style = "Omnivore"
        else:
            style = "not-sure-yet"
        print style
    else:
        pass
    return style
    print style

eating_style = None
my_diet(1, eating_style)
print eating_style
</code>```

What was printed on the console was: (assuming choice = "A")

Carnivore

Carnivore

None

Does this mean that eating_style is immutable? If so, how should I change the function to assign a different value to eating_style?

答:
Your argument is passed as a value. Assigning a new value won't have any effect on it. You can just return a new string like this.

```<code>def my_diet(event):
    if event == 1:
        choice = raw_input("""What type of animal are you?
        A) Carnivore
        B) Herbivore
        C) Omnivore
        """)
        style = ""
        if choice == "A":
            style = "Carnivore"
        elif choice == "B":
            style = "Herbivore"
        elif choice == "C":
            style = "Omnivore"
        else:
            style = "not-sure-yet"
    else:
        pass
    return style

eating_style = my_diet(1)
print eating_style
</code>```

Check this link for more information.
How do I pass a variable by reference?

Body:
def my_diet(event, style):
    if event == 1:
        choice = raw_input("""What type of animal are you?
        A) Carnivore
        B) Herbivore
        C) Omnivore
        """)
        if choice == "A":
            style = "Carnivore"
            print style
        elif choice == "B":
            style = "Herbivore"
        elif choice == "C":
            style = "Omnivore"
        else:
            style = "not-sure-yet"
        print style
    else:
        pass
    return style
    print style

eating_style = None
my_diet(1, eating_style)
print eating_style

What was printed on the console was: (assuming choice = "A")

Carnivore

Carnivore

None

Does this mean that eating_style is immutable? If so, how should I change the function to assign a different value to eating_style?

Body:
Your argument is passed as a value. Assigning a new value won't have any effect on it. You can just return a new string like this.

def my_diet(event):
    if event == 1:
        choice = raw_input("""What type of animal are you?
        A) Carnivore
        B) Herbivore
        C) Omnivore
        """)
        style = ""
        if choice == "A":
            style = "Carnivore"
        elif choice == "B":
            style = "Herbivore"
        elif choice == "C":
            style = "Omnivore"
        else:
            style = "not-sure-yet"
    else:
        pass
    return style

eating_style = my_diet(1)
print eating_style

Check this link for more information.
How do I pass a variable by reference?


问:
SQL Join 2 tables
I have two tables one named Person, which contains columns ID and Name and the second one, named Relation, which contains two columns, each of which contains an ID of a Person. It's about a relation between customer and serviceman. I'd like to Join these two tables so that I'll have names of people in every relation. Is it possible to write this query with some kind of joining?

EDIT::

I must do something wrong, but it's not working. I had tried a lot of forms of so looking queries, but I had been only getting one column or some errors. It's actually the school task, I have it already done (with different JOIN query). Firstly I had been trying to do this, but I'd failed: It seems to be very common situation, so I don't know why it's too complicated for me..

Here are my tables:

```<code>CREATE TABLE Oprava..(Repair) (
  KodPodvozku INTEGER PRIMARY KEY REFERENCES Automobil(KodPodvozku),
  IDzakaznika..(IDcustomer) INTEGER REFERENCES Osoba(ID),
  IDzamestnance..(IDemployee) INTEGER REFERENCES Osoba(ID)
);

CREATE TABLE Osoba..(Person) (
  ID INTEGER CONSTRAINT primaryKeyOsoba PRIMARY KEY ,
  Jmeno..(Name) VARCHAR(256) NOT NULL,
  OP INTEGER UNIQUE NOT NULL
);
</code>```

It's in Czech, but the words in brackets after ".." are english equivalents.
PS: I am using Oracle SQL.

答:
```<code>SELECT *
FROM Relation
INNER JOIN Person P1
ON P1.ID = Relation.FirstPersonID
INNER JOIN Person P2
ON P2.ID = Relation.SecondPersonID
</code>```

Title: SQL Join 2 tables

Body:
I have two tables one named Person, which contains columns ID and Name and the second one, named Relation, which contains two columns, each of which contains an ID of a Person. It's about a relation between customer and serviceman. I'd like to Join these two tables so that I'll have names of people in every relation. Is it possible to write this query with some kind of joining?

EDIT::

I must do something wrong, but it's not working. I had tried a lot of forms of so looking queries, but I had been only getting one column or some errors. It's actually the school task, I have it already done (with different JOIN query). Firstly I had been trying to do this, but I'd failed: It seems to be very common situation, so I don't know why it's too complicated for me..

Here are my tables:

CREATE TABLE Oprava..(Repair) (
  KodPodvozku INTEGER PRIMARY KEY REFERENCES Automobil(KodPodvozku),
  IDzakaznika..(IDcustomer) INTEGER REFERENCES Osoba(ID),
  IDzamestnance..(IDemployee) INTEGER REFERENCES Osoba(ID)
);

CREATE TABLE Osoba..(Person) (
  ID INTEGER CONSTRAINT primaryKeyOsoba PRIMARY KEY ,
  Jmeno..(Name) VARCHAR(256) NOT NULL,
  OP INTEGER UNIQUE NOT NULL
);

It's in Czech, but the words in brackets after ".." are english equivalents.
PS: I am using Oracle SQL.