问:
How to register console command from package in Laravel 5?
Since Laravel 5, it is interest to me - how to register and use console command from package in Laravel 5.

As in laracast discuss https://laracasts.com/discuss/channels/tips/developing-your-packages-in-laravel-5, i create a directory structure, add my package to autoload and create a service provider

```<code><?php namespace Goodvin\EternalTree;

use Console\InstallCommand;
use Illuminate\Support\ServiceProvider;

class EternalTreeServiceProvider extends ServiceProvider
{
    public function boot()
    {

    }

    public function register()
    {
        $this->registerCommands();
    }

    protected function registerCommands()
    {
        $this->registerInstallCommand();
    }

    protected function registerInstallCommand()
    {
        $this->app->singleton('command.eternaltree.install', function($app) {

            return new InstallCommand();
        });
    }

    public function provides()
    {
        return [

            'command.eternaltree.install'
        ];
    }
}
</code>```

My InstallCommand.php script stored in /src/Console

```<code><?php namespace Goodvin\EternalTree\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class InstallCommand extends Command {

    protected $name = 'install:eternaltree';
    protected $description = 'Command for EternalTree migration & model install.';

    public function __construct()
    {
        parent::__construct();
    }

    public function fire()
    {
        $this->info('Command eternaltree:install fire');
    }

}
</code>```

I register service provider in app.php & execute dump-autoload. But when i try to execute

```<code>php artisan eternaltree:install
</code>```

it show me

```<code>[InvalidArgumentException] There are no commands defined in the "eternaltree" namespace.
</code>```

I think my command is not registered by service provider, because php artisan list does not show my command. Can anyone explain to me what is the right way to register commands in own package in Laravel 5 ?

答:
Better late than never.

You were trying to call eternaltree:install but you registered the command as install:eternaltree.

Your answer is correct... but there was no need for the registerCommands() and registerInstallCommands() methods. Keep your code lean by just calling the commands() method from within the register() method.

Body:
Since Laravel 5, it is interest to me - how to register and use console command from package in Laravel 5.

As in laracast discuss https://laracasts.com/discuss/channels/tips/developing-your-packages-in-laravel-5, i create a directory structure, add my package to autoload and create a service provider

<?php namespace Goodvin\EternalTree;

use Console\InstallCommand;
use Illuminate\Support\ServiceProvider;

class EternalTreeServiceProvider extends ServiceProvider
{
    public function boot()
    {

    }

    public function register()
    {
        $this->registerCommands();
    }

    protected function registerCommands()
    {
        $this->registerInstallCommand();
    }

    protected function registerInstallCommand()
    {
        $this->app->singleton('command.eternaltree.install', function($app) {

            return new InstallCommand();
        });
    }

    public function provides()
    {
        return [

            'command.eternaltree.install'
        ];
    }
}

My InstallCommand.php script stored in /src/Console

<?php namespace Goodvin\EternalTree\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class InstallCommand extends Command {

    protected $name = 'install:eternaltree';
    protected $description = 'Command for EternalTree migration & model install.';

    public function __construct()
    {
        parent::__construct();
    }

    public function fire()
    {
        $this->info('Command eternaltree:install fire');
    }

}

I register service provider in app.php & execute dump-autoload. But when i try to execute

php artisan eternaltree:install

it show me

[InvalidArgumentException] There are no commands defined in the "eternaltree" namespace.

I think my command is not registered by service provider, because php artisan list does not show my command. Can anyone explain to me what is the right way to register commands in own package in Laravel 5 ?


来源: stackexchange

问:
Accessing an associative array by integer index in PHP
I want to set the value of an associative array using the array index of the key/value pair.  For example:

```<code>$my_arr = array( "bling" => "some bling", "bling2" => "lots O bling" );
$my_arr[1] = "not so much bling";  // Would change the value with key bling2.
</code>```

How can this be accomplish this without using the key string?

答:
Use array_keys.</p>
```<code>$keys = array_keys($my_arr);
$my_arr[$keys[1]] = "not so much bling";
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I want to set the value of an associative array using the array index of the key/value pair.  For example:

$my_arr = array( "bling" => "some bling", "bling2" => "lots O bling" );
$my_arr[1] = "not so much bling";  // Would change the value with key bling2.

How can this be accomplish this without using the key string?

Body:
Use array_keys.

$keys = array_keys($my_arr);
$my_arr[$keys[1]] = "not so much bling";

ContentLicense: CC BY-SA 4.0


问:
SQL Server to Oracle conversion
I am unable to convert this SQL Server code to Oracle code. I am not SQL expert, can anyone help in converting this code to Oracle compatible.</p>

```<code> Declare @lvl as int
 Declare @rows as int
 DECLARE @foo as Table(
     KV_MANAGERNR int,
     KV_PERSONNR varchar(10),
     ord int,
     lvl int)

INSERT @foo (KV_MANAGERNR, KV_PERSONNR, ord, lvl)
select KV_MANAGERNR, KV_PERSONNR, row_number() over(order by KV_PERSONNR), 0
    from PERSONSMANAGER where KV_MANAGERNR='127723'

set @rows=@@ROWCOUNT
set @lvl=0

--Do recursion
WHILE @rows > 0
BEGIN
    set @lvl = @lvl + 1

    INSERT @foo (KV_MANAGERNR, KV_PERSONNR, ord, lvl)
    SELECT DISTINCT b.KV_MANAGERNR, b.KV_PERSONNR, row_number() over(order
    by b.KV_PERSONNR), @lvl
    FROM PERSONSMANAGER b
     inner join @foo f on b.KV_MANAGERNR = f.KV_PERSONNR
     --might be multiple paths to this recursion so eliminate duplicates
     left join @foo dup on dup.KV_PERSONNR = b.KV_PERSONNR
     WHERE f.lvl = @lvl-1 and dup.KV_PERSONNR is null

    set @rows=@@ROWCOUNT
END

SELECT DISTINCT KV_PERSONNR from @foo order by KV_PERSONNR
</code>```

答:
```<code>DECLARE
    v_lvl Number:=0;
    v_rows number:=1;
BEGIN
    INSERT INTO nt_list_0 (KV_MANAGERNR, KV_PERSONNR, ord, lvl)
        select KV_MANAGERNR, KV_PERSONNR, row_number() over(order by
        KV_PERSONNR), 0  from PERSONSMANAGER where KV_MANAGERNR='100047';

    WHILE v_rows>0
    LOOP
        v_lvl := v_lvl +1;

        INSERT INTO nt_list_0 (KV_MANAGERNR, KV_PERSONNR, ord, lvl)
        SELECT DISTINCT b.KV_MANAGERNR, b.KV_PERSONNR, row_number()
          over(order by b.KV_PERSONNR), v_lvl
        FROM PERSONSMANAGER b
        inner join nt_list_0 f on b.KV_MANAGERNR = f.KV_PERSONNR
        left join nt_list_0 dup on dup.KV_PERSONNR = b.KV_PERSONNR
        WHERE f.lvl = v_lvl-1 and dup.KV_PERSONNR is null;

        v_rows := sql%rowcount;
    END LOOP;
END;
</code>```

ContentLicense: CC BY-SA 3.0

Title: SQL Server to Oracle conversion

Body:
I am unable to convert this SQL Server code to Oracle code. I am not SQL expert, can anyone help in converting this code to Oracle compatible.

 Declare @lvl as int
 Declare @rows as int
 DECLARE @foo as Table(
     KV_MANAGERNR int,
     KV_PERSONNR varchar(10),
     ord int,
     lvl int)

INSERT @foo (KV_MANAGERNR, KV_PERSONNR, ord, lvl)
select KV_MANAGERNR, KV_PERSONNR, row_number() over(order by KV_PERSONNR), 0
    from PERSONSMANAGER where KV_MANAGERNR='127723'

set @rows=@@ROWCOUNT
set @lvl=0

--Do recursion
WHILE @rows > 0
BEGIN
    set @lvl = @lvl + 1

    INSERT @foo (KV_MANAGERNR, KV_PERSONNR, ord, lvl)
    SELECT DISTINCT b.KV_MANAGERNR, b.KV_PERSONNR, row_number() over(order
    by b.KV_PERSONNR), @lvl
    FROM PERSONSMANAGER b
     inner join @foo f on b.KV_MANAGERNR = f.KV_PERSONNR
     --might be multiple paths to this recursion so eliminate duplicates
     left join @foo dup on dup.KV_PERSONNR = b.KV_PERSONNR
     WHERE f.lvl = @lvl-1 and dup.KV_PERSONNR is null

    set @rows=@@ROWCOUNT
END

SELECT DISTINCT KV_PERSONNR from @foo order by KV_PERSONNR


问:
Python 3.6 My loop carries on applying to a list even when the list is removed
I am trying to build a turn based battle game but I am encountering a problem with damage infliction.

roomMonsters is a list like: [['A Zombie' , 2 , 2 , 3],['A Zombie , 2 , 2, 3]]

```<code>def heroAttack(roomMonsters , heroes):
    target = int(input('Which monster shall you attack? ')) #Which monster to attack
    attacker = int(input('Which hero shall you attack with? ')) #Which hero to attack with
    damage = int(random.randint(int(heroes[attacker][2]) , heroes[attacker][2])*2)    #Calculates damage
    for number in range(0,damage):
        while roomMonsters[target][1] > 0:
            roomMonsters[target][1] = roomMonsters[target][1]-1
            #print('Debug, inflicting pain')

    print('Your' , heroes[attacker][0] , 'attacked' , roomMonsters[target][0] , 'for' , damage , 'damage.') #Prints the result
    checkForMonsterDeath(heroes,roomMonsters,attacker,target)
    return roomMonsters
</code>```

I expect the result to inflict damage to one list entry and then stop, so it inflicts damage to the zombie which is attacked.

However, it inflicts the damage to all zombies.I think it may be because the checkForMonsterDeath removes a monster from the list but I cannot see how that leads to the damage being inflicted to all the monsters of the same type.

Gameplay looks like this accordingly:

```<code>You enter the room and monsters lie ahead of you...
You can see:
0 A Zombie with 2 HP.
1 A Spider with 5 HP.
2 A Zombie with 2 HP.
Which monster shall you attack? 0
Which hero shall you attack with? 1
Your Wielder of Zzzzap attacked A Zombie for 14 damage.
A Zombie exploded in a fiery ball of gloop.
You enter the room and monsters lie ahead of you...
You can see:
0 A Spider with 5 HP.
1 A Zombie with 0 HP.
</code>```

As you can see the damage is inflicted to all the zombies, not just the one who was attacked.

Apologies for any bad formatting, this is my first time here and thanks for your help.

答:
The issue looks like it is one of the usual caveat that exists with list duplication. (Similar issue :  List of lists changes reflected across sublists unexpectedly)

The problem is the following : the mutiple lists you have for each zombies are actually one and the same, which means that if you try to modify one element in one of the copies then the changes happens in all the copies (because they are the same object). So to have your several zombies with each a list of their own you will have to make independant copies of the original list (.copy() will suffice here). See that example :

```<code>zombieList = ['A Zombie' , 2 , 2 , 3]
badCopyRoomMonsters = [zombieList,zombieList]
#trying to deal damage to only the first zombie
badCopyRoomMonsters[0][1] = 0
print(badCopyRoomMonsters)
print(zombieList) #even the original list got modified because they are all references to the same object

zombieList = ['A Zombie' , 2 , 2 , 3]
goodCopyRoomMonsters =[zombieList.copy(),zombieList.copy()]
#trying to deal damage to only the first zombie
goodCopyRoomMonsters[0][1] = 0
print(goodCopyRoomMonsters)
print(zombieList) #now it's all behaving as expected
</code>```

Body:
I am trying to build a turn based battle game but I am encountering a problem with damage infliction.

roomMonsters is a list like: [['A Zombie' , 2 , 2 , 3],['A Zombie , 2 , 2, 3]]

def heroAttack(roomMonsters , heroes):
    target = int(input('Which monster shall you attack? ')) #Which monster to attack
    attacker = int(input('Which hero shall you attack with? ')) #Which hero to attack with
    damage = int(random.randint(int(heroes[attacker][2]) , heroes[attacker][2])*2)    #Calculates damage
    for number in range(0,damage):
        while roomMonsters[target][1] > 0:
            roomMonsters[target][1] = roomMonsters[target][1]-1
            #print('Debug, inflicting pain')

    print('Your' , heroes[attacker][0] , 'attacked' , roomMonsters[target][0] , 'for' , damage , 'damage.') #Prints the result
    checkForMonsterDeath(heroes,roomMonsters,attacker,target)
    return roomMonsters

I expect the result to inflict damage to one list entry and then stop, so it inflicts damage to the zombie which is attacked.

However, it inflicts the damage to all zombies.I think it may be because the checkForMonsterDeath removes a monster from the list but I cannot see how that leads to the damage being inflicted to all the monsters of the same type.

Gameplay looks like this accordingly:

You enter the room and monsters lie ahead of you...
You can see:
0 A Zombie with 2 HP.
1 A Spider with 5 HP.
2 A Zombie with 2 HP.
Which monster shall you attack? 0
Which hero shall you attack with? 1
Your Wielder of Zzzzap attacked A Zombie for 14 damage.
A Zombie exploded in a fiery ball of gloop.
You enter the room and monsters lie ahead of you...
You can see:
0 A Spider with 5 HP.
1 A Zombie with 0 HP.

As you can see the damage is inflicted to all the zombies, not just the one who was attacked.

Apologies for any bad formatting, this is my first time here and thanks for your help.

Body:
The issue looks like it is one of the usual caveat that exists with list duplication. (Similar issue :  List of lists changes reflected across sublists unexpectedly)

The problem is the following : the mutiple lists you have for each zombies are actually one and the same, which means that if you try to modify one element in one of the copies then the changes happens in all the copies (because they are the same object). So to have your several zombies with each a list of their own you will have to make independant copies of the original list (.copy() will suffice here). See that example :

zombieList = ['A Zombie' , 2 , 2 , 3]
badCopyRoomMonsters = [zombieList,zombieList]
#trying to deal damage to only the first zombie
badCopyRoomMonsters[0][1] = 0
print(badCopyRoomMonsters)
print(zombieList) #even the original list got modified because they are all references to the same object

zombieList = ['A Zombie' , 2 , 2 , 3]
goodCopyRoomMonsters =[zombieList.copy(),zombieList.copy()]
#trying to deal damage to only the first zombie
goodCopyRoomMonsters[0][1] = 0
print(goodCopyRoomMonsters)
print(zombieList) #now it's all behaving as expected


问:
getter function is not working when getline is used

I am using the getline to get string input from the user as shown below.

```<code>            cout << "Enter full name : ";
            cin >> fullname;
            cin.ignore();
            getline(cin, fullname);
</code>```

getline is working correctly I am able to write full name with white space. But the problem is I am not able to get the fullname when getter function is used.

```<code> if (strcmp(u[i]->getemail(), email) == 0) { // if entered email matches the email
                cout << "User name -->" << u[i]->getusername()<<endl;    //member details is displayed
                cout << "Full name -->" << u[i]->getfullname()<<endl;
                cout << "Password  -->" << u[i]->getpassword()<<endl;
                flag = true;
                break;
</code>```

By the way below is my setter/getter functions for the variable fullname

```<code>  string User::getfullname()

{
    return fullname;
}

void User::setfullname(string fullname)

{
    fullname = fullname;
}
</code>```

This is the constructor

```<code>  User::User(char* username, char* password, string infullname, char* email)
{                       //constructor
    strcpy(this->username, username);
    strcpy(this->password, password);
    setfullName(infullname);
    strcpy(this->email, email);
}
</code>```

This is the Out put
https://www.dropbox.com/s/oya9wtswd3phq7o/error.jpg?dl=0

I am a newbie to C++ and would appreciate if you can point out the mistake.

答:
By reading your code, I think the problem might be coming from your setter function.

```<code>void User::setfullname(string fullname)
{
    fullname = fullname;
}
</code>```

The function parameter and your class attribute share the same name. You need to identify by using the this keyword. Or change the function's parameter name.

Something of the likes of this:

```<code>void User::setFullName(string str)
{
    this->fullName = str;
}
</code>```

Body:
I am using the getline to get string input from the user as shown below.

            cout << "Enter full name : ";
            cin >> fullname;
            cin.ignore();
            getline(cin, fullname);

getline is working correctly I am able to write full name with white space. But the problem is I am not able to get the fullname when getter function is used.

 if (strcmp(u[i]->getemail(), email) == 0) { // if entered email matches the email
                cout << "User name -->" <getusername()<<endl;    //member details is displayed
                cout << "Full name -->" <getfullname()<<endl;
                cout << "Password  -->" <getpassword()<<endl;
                flag = true;
                break;

By the way below is my setter/getter functions for the variable fullname

  string User::getfullname()

{
    return fullname;
}

void User::setfullname(string fullname)

{
    fullname = fullname;
}

This is the constructor

  User::User(char* username, char* password, string infullname, char* email)
{                       //constructor
    strcpy(this->username, username);
    strcpy(this->password, password);
    setfullName(infullname);
    strcpy(this->email, email);
}

This is the Out put
https://www.dropbox.com/s/oya9wtswd3phq7o/error.jpg?dl=0

I am a newbie to C++ and would appreciate if you can point out the mistake.

Body:
By reading your code, I think the problem might be coming from your setter function.

void User::setfullname(string fullname)
{
    fullname = fullname;
}

The function parameter and your class attribute share the same name. You need to identify by using the this keyword. Or change the function's parameter name.

Something of the likes of this:

void User::setFullName(string str)
{
    this->fullName = str;
}


问:
Understanding event listeners in java
I'm new to java and I'm still trying to understand the language, so I apologize if this question might sound noobish.

There's something I don't understand about listeners, sometime you can see a listener declared in such a fashion:

```<code>    private View.OnClickListener onSave=new View.OnClickListener() {
public void onClick(View v) {

// Some code

}

};
</code>```

or:

```<code>javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
</code>```

The thing that perplex me the most is that semicolon and parenthesis after the end of the method.

I understand inner classes for the purpose of having multiple listeners, but I don't understand this mixed declaration of variables and method.

Which purpose it has?

How is it declared?

WTF? :P

cheers :)

答:
That code applies anonymous classes. Search and read for this topic.

The semicolon terminates the assignment respectively the method invocation.

PS. I always was thinking the name is something misleading because what you really get is an Object.

Title: Understanding event listeners in java

Body:
I'm new to java and I'm still trying to understand the language, so I apologize if this question might sound noobish.

There's something I don't understand about listeners, sometime you can see a listener declared in such a fashion:

    private View.OnClickListener onSave=new View.OnClickListener() {
public void onClick(View v) {

// Some code

}

};

or:

javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });

The thing that perplex me the most is that semicolon and parenthesis after the end of the method.

I understand inner classes for the purpose of having multiple listeners, but I don't understand this mixed declaration of variables and method.

Which purpose it has?

How is it declared?

WTF? :P

cheers :)


问:
C# - serializing list works, but deserializing returns empty list
I have an odd problem with XML deserialization in C#. Serializing the object works as expected, but deserializing makes the list-valued attribute Files empty.

```<code>using System;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Text;

namespace Converter
{
   [Serializable]
   [XmlRoot("userinput")]
   public class Input
   {

      [XmlArray("files")]
      [XmlArrayItem(Type = typeof(FilePair), ElementName = "filepair")]
      public List<FilePair> Files;

      public Input()
      { }

   }
}
</code>```

and the element:

```<code>using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Converter
{
   [Serializable]
    public class FilePair
    {
        [XmlElement("file1")]
        public string File1;

        [XmlElement("file2")]
        public string File2;

        public FilePair() { }

    }

    public enum FileSource { Foo, Bar };
}
</code>```

and a sample XML:

```<code><userinput>
   <files>
      <filepair>
         <file1>foo</file1>
         <file2>bar</file2>
      </filepair>
      <filepair>
         <file1>foo</file1>
         <file2>bar</file2>
      </filepair>
   </files>
</userinput>
</code>```

答:
If I take your code, fix the [XmlElement("file2")], and use:

```<code>    var xml = @"<userinput>
<files>
  <filepair>
     <file1>foo</file1>
     <file2>bar</file2>
  </filepair>
  <filepair>
     <file1>foo</file1>
     <file2>bar</file2>
  </filepair>
</files>
</userinput>";
    using (var reader = new StringReader(xml))
    {
        var obj = (Input)new XmlSerializer(typeof(Input)).Deserialize(reader);
        foreach(var file in obj.Files)
        {
            Console.WriteLine($"{file.File1}, {file.File2}");
        }
    }
</code>```

then: it works. The output is:

```<code>foo, bar
foo, bar
</code>```

So: whatever the problem is: you've fixed it when creating your minimal sample.

So now the question becomes: what is different between your minimal sample and your real code? Answer that, and you'll answer the question for yourself.

Body:
I have an odd problem with XML deserialization in C#. Serializing the object works as expected, but deserializing makes the list-valued attribute Files empty.

using System;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Text;

namespace Converter
{
   [Serializable]
   [XmlRoot("userinput")]
   public class Input
   {

      [XmlArray("files")]
      [XmlArrayItem(Type = typeof(FilePair), ElementName = "filepair")]
      public List<FilePair> Files;

      public Input()
      { }

   }
}

and the element:

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Converter
{
   [Serializable]
    public class FilePair
    {
        [XmlElement("file1")]
        public string File1;

        [XmlElement("file2")]
        public string File2;

        public FilePair() { }

    }

    public enum FileSource { Foo, Bar };
}

and a sample XML:

<userinput>
   <files>
      <filepair>
         <file1>foo</file1>
         <file2>bar</file2>
      </filepair>
      <filepair>
         <file1>foo</file1>
         <file2>bar</file2>
      </filepair>
   </files>
</userinput>

Body:
If I take your code, fix the [XmlElement("file2")], and use:

    var xml = @"<userinput>
<files>
  <filepair>
     <file1>foo</file1>
     <file2>bar</file2>
  </filepair>
  <filepair>
     <file1>foo</file1>
     <file2>bar</file2>
  </filepair>
</files>
</userinput>";
    using (var reader = new StringReader(xml))
    {
        var obj = (Input)new XmlSerializer(typeof(Input)).Deserialize(reader);
        foreach(var file in obj.Files)
        {
            Console.WriteLine($"{file.File1}, {file.File2}");
        }
    }

then: it works. The output is:

foo, bar
foo, bar

So: whatever the problem is: you've fixed it when creating your minimal sample.

So now the question becomes: what is different between your minimal sample and your real code? Answer that, and you'll answer the question for yourself.


问:
Eclipse doesn't stop at breakpoints
Eclipse 3.5.2 is not stopping in breakpoints. It's as if the debugger is using an older version of the source file.

Tried the usual refresh, clean all projects, build all, with no change.

Already in debug mode and the break point is checked.

*ok ended up deleting the whole project and checking it out again. but still curious what the issue was.

答:
I use the Eclipse FileSync plugin for live remote debugging. Make sure you tick Allow different target folders & edit the Target folder file setting in the tree view.

Setting the Default target folder by the Browse... button without Allow different target folders will set all folders to the same target (I had both libs & classes set to the default for libs so my breakpoints did not update).

Title: Eclipse doesn't stop at breakpoints


问:
When Dialog-box is dismiss default keyboard is still visible?
Problem

I want to change mobile number using OTP verification. I have a change button on user profile screen. While clicking on change button, I am opening one dialog box. Once dialog-box will open user is typing his new contact number and pressing resend otp button of dialog box then dialog box will dismiss and key board should also hide. But, keyboard is not hiding. One thing after change_no_dialog-box is dismiss I am showing one more dialog-box for Enter OTP once user will enter the OTP and press submit button again same problem is coming keyboard is not hiding.

Here what i have tried

Edittext on Dialog box

```<code>        <android.support.design.widget.TextInputLayout
            android:layout_marginTop="36dp"
            android:theme="@style/TextLabel"
            android:id="@+id/no_layout"
            android:layout_marginLeft="24dp"
            android:layout_marginRight="24dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <EditText
                android:paddingLeft="8dp"
                android:id="@+id/dialog_box_mobile"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:inputType="number"
                android:imeOptions="actionDone"
                android:singleLine="true"
                android:textColorHint="@color/navigation_header"
                android:hint="@string/mobno"
                android:textSize="@dimen/sisteen"
                android:maxLength="10"/>

        </android.support.design.widget.TextInputLayout>
</code>```

Onclick of resend otp button

```<code>  if (v.getId() == R.id.resend_otp_btn) {

            if (dialog_box_mobile.getText().toString().equals(user_mobile_no)) {
                hideKeyboard(EditProfileActivity.this);
                dialog.dismiss();
                bottomSnackbarMessage("It looks like same number !");
                // Toast.makeText(EditProfileActivity.this, "It looks like same number!", Toast.LENGTH_SHORT).show();

            } else {

                if (dialog_box_mobile.getText().length() != 0) {
                    if (dialog_box_mobile.getText().toString().length() < 10) {

                        dialog_box_mobile.setError("Invalid phone number !");
                        resend_otp_btn.setClickable(true);

                    } else {
                        if (CheckNetwork.isConnected()) {
                            resend_otp_btn.setClickable(false);
                            dialog.dismiss();
                            startPhoneNumberVerification(dialog_box_mobile.getText().toString());
                        } else {
                            dialog.dismiss();
                            bottomSnackbar();
                        }

                    }

                } else if (dialog_box_mobile.getText().toString().equalsIgnoreCase("")) {
                    dialog_box_mobile.setError("Mobile number required");
                    resend_otp_btn.setClickable(true);

                }

            }

        }
</code>```

Keyboard hide method

```<code>  public static void hideKeyboard(Activity activity) {
        InputMethodManager imm = (InputMethodManager)
             activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        //Find the currently focused view, so we can grab the correct window
              token from it.
        View view = activity.getCurrentFocus();
        //If no view currently has focus, create a new one, just so we can
          grab a window token from it
        if (view == null) {
            view = new View(activity);
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
</code>```

Adding this on mainifest and every Activity Layout

```<code> android:windowSoftInputMode="stateHidden"
</code>```

kindly see the ScreenShot

On change button clicked opening dialog

Here i want to hide keyboard while dialog box is dismiss

答:
try this:

```<code>        public static void hideKeyboard(EditText edt) {
            InputMethodManager imm = (InputMethodManager)
                 edt.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
        }
</code>```

Also Add below dismiss listener:

```<code>           dialogBox.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialogInterface) {
                   hideKeyBoard(editText);
            dialogBox.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

        }
    });
</code>```

Body:
Problem

I want to change mobile number using OTP verification. I have a change button on user profile screen. While clicking on change button, I am opening one dialog box. Once dialog-box will open user is typing his new contact number and pressing resend otp button of dialog box then dialog box will dismiss and key board should also hide. But, keyboard is not hiding. One thing after change_no_dialog-box is dismiss I am showing one more dialog-box for Enter OTP once user will enter the OTP and press submit button again same problem is coming keyboard is not hiding.

Here what i have tried

Edittext on Dialog box

        <android.support.design.widget.TextInputLayout
            android:layout_marginTop="36dp"
            android:theme="@style/TextLabel"
            android:id="@+id/no_layout"
            android:layout_marginLeft="24dp"
            android:layout_marginRight="24dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <EditText
                android:paddingLeft="8dp"
                android:id="@+id/dialog_box_mobile"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:inputType="number"
                android:imeOptions="actionDone"
                android:singleLine="true"
                android:textColorHint="@color/navigation_header"
                android:hint="@string/mobno"
                android:textSize="@dimen/sisteen"
                android:maxLength="10"/>

        </android.support.design.widget.TextInputLayout>

Onclick of resend otp button

  if (v.getId() == R.id.resend_otp_btn) {

            if (dialog_box_mobile.getText().toString().equals(user_mobile_no)) {
                hideKeyboard(EditProfileActivity.this);
                dialog.dismiss();
                bottomSnackbarMessage("It looks like same number !");
                // Toast.makeText(EditProfileActivity.this, "It looks like same number!", Toast.LENGTH_SHORT).show();

            } else {

                if (dialog_box_mobile.getText().length() != 0) {
                    if (dialog_box_mobile.getText().toString().length() < 10) {

                        dialog_box_mobile.setError("Invalid phone number !");
                        resend_otp_btn.setClickable(true);

                    } else {
                        if (CheckNetwork.isConnected()) {
                            resend_otp_btn.setClickable(false);
                            dialog.dismiss();
                            startPhoneNumberVerification(dialog_box_mobile.getText().toString());
                        } else {
                            dialog.dismiss();
                            bottomSnackbar();
                        }

                    }

                } else if (dialog_box_mobile.getText().toString().equalsIgnoreCase("")) {
                    dialog_box_mobile.setError("Mobile number required");
                    resend_otp_btn.setClickable(true);

                }

            }

        }

Keyboard hide method

  public static void hideKeyboard(Activity activity) {
        InputMethodManager imm = (InputMethodManager)
             activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        //Find the currently focused view, so we can grab the correct window
              token from it.
        View view = activity.getCurrentFocus();
        //If no view currently has focus, create a new one, just so we can
          grab a window token from it
        if (view == null) {
            view = new View(activity);
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

Adding this on mainifest and every Activity Layout

 android:windowSoftInputMode="stateHidden"

kindly see the ScreenShot

On change button clicked opening dialog

Here i want to hide keyboard while dialog box is dismiss

Body:
try this:

        public static void hideKeyboard(EditText edt) {
            InputMethodManager imm = (InputMethodManager)
                 edt.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
        }

Also Add below dismiss listener:

           dialogBox.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialogInterface) {
                   hideKeyBoard(editText);
            dialogBox.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

        }
    });


问:
Query Check Status from other table
I have following query

```<code>select * from user_profile
</code>```

Now i want to add where condition check user status from other table (users)

```<code>select * from user_profile,users where users.status!=0
</code>```

Please Do Not Recommend Join  i following old join query

Thanks

答:
Assuming you have a relation column (say user_id or perhaps profile_id or something -- not sure until you share sample data as requested.) between the two tables, you can join the two table and filter the rows like this:

```<code>select *
from user_profile p
join users u on p.user_id = u.user_id
where u.status != 0;
</code>```

Title: Query Check Status from other table

Body:
I have following query

select * from user_profile

Now i want to add where condition check user status from other table (users)

select * from user_profile,users where users.status!=0

Please Do Not Recommend Join  i following old join query

Thanks

Body:
Assuming you have a relation column (say user_id or perhaps profile_id or something -- not sure until you share sample data as requested.) between the two tables, you can join the two table and filter the rows like this:

select *
from user_profile p
join users u on p.user_id = u.user_id
where u.status != 0;


问:
x86 or x64 disassembler lib
I know o some disassemble libs , but what I'm looking for is one that has an api like:

```<code>void * findAddrOfFirstInstructionStartingFrom( void * startAddress , InstructionType instruction);

void* addr = findAddrOfFirstInstructionStartingFrom(startAddress , JMP);
</code>```

and other apis smiler to this one like search for something specific not disassemble all instructions stating from an address and get all sorts of info because it slow if you only want to find something specific not everything.

If you know any pls let me know , if there isn't any pls tell me one that is open source and easy to modify.

答: What you probably want is not just a library, but some Disassembler Framework. Have a look at IDA-Pro, which also provides a versatile scripting interface (and a disassembler API)</p>

Title: x86 or x64 disassembler lib

Body:
I know o some disassemble libs , but what I'm looking for is one that has an api like:

void * findAddrOfFirstInstructionStartingFrom( void * startAddress , InstructionType instruction);

void* addr = findAddrOfFirstInstructionStartingFrom(startAddress , JMP);

and other apis smiler to this one like search for something specific not disassemble all instructions stating from an address and get all sorts of info because it slow if you only want to find something specific not everything.

If you know any pls let me know , if there isn't any pls tell me one that is open source and easy to modify.


问:
PRIME NUMBER(the if function and being divided by 2)
Hi I'm having a little problem about prime function.

```<code>public static boolean isPrime(long num) {

    for (long i=3; i <num/2; i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}
</code>```

I don't understand why it has to be num/2 and the if(num % i == 0).
so does it mean that if
num = 10 and i = 4 which would result to 2. makes 4 a prime number?

sorry if it's a stupid question, I just started coding \m/

edit: also, can someone explain the  if(num % 1 ==0)

答:
if you want to write a code to check whether is it is prime number or not then you need to change loop initialization.

long i=3  --> long i=2. Because prime number should not be divisible by any number other than 1. So you should start divide the number by 2,

Body:
Hi I'm having a little problem about prime function.

public static boolean isPrime(long num) {

    for (long i=3; i <num/2; i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

I don't understand why it has to be num/2 and the if(num % i == 0).
so does it mean that if
num = 10 and i = 4 which would result to 2. makes 4 a prime number?

sorry if it's a stupid question, I just started coding \m/

edit: also, can someone explain the  if(num % 1 ==0)


问:
Spring Boot Ambiguous mapping. Cannot map method
I have 2 REST controllers in my Spring Boot application with simple CRUD operations.

REST controller, that is mapped to "/json/currency"

```<code>package ua.alekstar.moneysaver.rest;

import org.springframework.web.bind.annotation.*;
import ua.alekstar.moneysaver.rest.currency.Currencies;
import ua.alekstar.moneysaver.rest.currency.Currency;
import ua.alekstar.moneysaver.service.CurrencyService;

import java.util.Collections;

@RestController("/json/currency")
public class CurrencyJsonRestController {

    private final CurrencyService currencyService;

    public CurrencyJsonRestController(CurrencyService currencyService) {
        this.currencyService = currencyService;
    }

    @GetMapping
    @ResponseBody
    public Currencies get(@RequestParam(required = false) Long id) {
        if (id == null) {
            return readAll();
        }
        return read(id);
    }

    private Currencies read(Long id) {
        return new Currencies(Collections.singletonList(currencyService.read(id)));
    }

    private Currencies readAll() {
        return new Currencies(currencyService.readAll());
    }

    @PostMapping
    public void post(@RequestBody Currency currency) {
        currencyService.create(currency.toEntity());
    }

    @PutMapping
    public void put(@RequestBody Currency currency) {
        currencyService.update(currency.toEntity());
    }

    @DeleteMapping
    public void delete(@RequestParam Long id) {
        currencyService.delete(id);
    }
}
</code>```

and REST controller, that is mapped to "/json/account"

```<code>package ua.alekstar.moneysaver.rest;

import org.springframework.web.bind.annotation.*;
import ua.alekstar.moneysaver.dao.entities.Currency;
import ua.alekstar.moneysaver.rest.account.Account;
import ua.alekstar.moneysaver.rest.account.Accounts;
import ua.alekstar.moneysaver.service.AccountService;
import ua.alekstar.moneysaver.service.CurrencyService;

import java.util.Collections;

@RestController("/json/account")
public class AccountJsonRestController {

    private final AccountService accountService;
    private final CurrencyService currencyService;

    public AccountJsonRestController(AccountService accountService, CurrencyService currencyService) {
        this.accountService = accountService;
        this.currencyService = currencyService;
    }

    @GetMapping
    @ResponseBody
    public Accounts get(@RequestParam(required = false) Long id) {
        if (id == null) {
            return readAll();
        }
        return read(id);
    }

    private Accounts read(Long id) {
        return new Accounts(Collections.singletonList(accountService.read(id)));
    }

    private Accounts readAll() {
        return new Accounts(accountService.readAll());
    }

    @PostMapping
    public void post(@RequestBody Account account) {
        accountService.create(toEntity(account));
    }

    private ua.alekstar.moneysaver.dao.entities.Account toEntity(Account account) {
        final Currency currency = currencyService.readByIsoCode(account.getCurrency());
        return new ua.alekstar.moneysaver.dao.entities.Account(account.getId(), account.getName(), currency);
    }

    @PutMapping
    public void put(@RequestBody Account account) {
        accountService.update(toEntity(account));
    }

    @DeleteMapping
    public void delete(@RequestParam Long id) {
        accountService.delete(id);
    }

}
</code>```

While I start my application I have an exception and I do not understand why it happens.

```/usr/lib/jvm/java-8-oracle/bin/java -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:/home/sasha/Applications/idea-IU-171.3780.107/lib/idea_rt.jar=32820:/home/sasha/Applications/idea-IU-171.3780.107/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/home/sasha/Documents/development/moneysaver/target/classes:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/1.5.3.RELEASE/spring-boot-starter-data-jpa-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter/1.5.3.RELEASE/spring-boot-starter-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot/1.5.3.RELEASE/spring-boot-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.5.3.RELEASE/spring-boot-autoconfigure-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.5.3.RELEASE/spring-boot-starter-logging-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar:/home/sasha/.m2/repository/ch/qos/logback/logback-core/1.1.11/logback-core-1.1.11.jar:/home/sasha/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar:/home/sasha/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.25/log4j-over-slf4j-1.7.25.jar:/home/sasha/.m2/repository/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-aop/1.5.3.RELEASE/spring-boot-starter-aop-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-aop/4.3.8.RELEASE/spring-aop-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/1.5.3.RELEASE/spring-boot-starter-jdbc-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/apache/tomcat/tomcat-jdbc/8.5.14/tomcat-jdbc-8.5.14.jar:/home/sasha/.m2/repository/org/apache/tomcat/tomcat-juli/8.5.14/tomcat-juli-8.5.14.jar:/home/sasha/.m2/repository/org/springframework/spring-jdbc/4.3.8.RELEASE/spring-jdbc-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/javax/transaction/javax.transaction-api/1.2/javax.transaction-api-1.2.jar:/home/sasha/.m2/repository/org/springframework/data/spring-data-jpa/1.11.3.RELEASE/spring-data-jpa-1.11.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/data/spring-data-commons/1.13.3.RELEASE/spring-data-commons-1.13.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-orm/4.3.8.RELEASE/spring-orm-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-context/4.3.8.RELEASE/spring-context-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-tx/4.3.8.RELEASE/spring-tx-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-beans/4.3.8.RELEASE/spring-beans-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/home/sasha/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.25/jcl-over-slf4j-1.7.25.jar:/home/sasha/.m2/repository/org/springframework/spring-aspects/4.3.8.RELEASE/spring-aspects-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.5.3.RELEASE/spring-boot-starter-web-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.5.3.RELEASE/spring-boot-starter-tomcat-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.14/tomcat-embed-core-8.5.14.jar:/home/sasha/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.5.14/tomcat-embed-el-8.5.14.jar:/home/sasha/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.14/tomcat-embed-websocket-8.5.14.jar:/home/sasha/.m2/repository/org/hibernate/hibernate-validator/5.3.5.Final/hibernate-validator-5.3.5.Final.jar:/home/sasha/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar:/home/sasha/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.8.8/jackson-databind-2.8.8.jar:/home/sasha/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar:/home/sasha/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.8/jackson-core-2.8.8.jar:/home/sasha/.m2/repository/org/springframework/spring-web/4.3.8.RELEASE/spring-web-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-webmvc/4.3.8.RELEASE/spring-webmvc-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-expression/4.3.8.RELEASE/spring-expression-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.1.Final/hibernate-jpa-2.0-api-1.0.1.Final.jar:/home/sasha/.m2/repository/org/hibernate/hibernate-core/5.2.10.Final/hibernate-core-5.2.10.Final.jar:/home/sasha/.m2/repository/org/jboss/logging/jboss-logging/3.3.1.Final/jboss-logging-3.3.1.Final.jar:/home/sasha/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar:/home/sasha/.m2/repository/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar:/home/sasha/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/home/sasha/.m2/repository/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.0.1.Final/jboss-transaction-api_1.2_spec-1.0.1.Final.jar:/home/sasha/.m2/repository/org/jboss/jandex/2.0.3.Final/jandex-2.0.3.Final.jar:/home/sasha/.m2/repository/com/fasterxml/classmate/1.3.3/classmate-1.3.3.jar:/home/sasha/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/home/sasha/.m2/repository/org/hibernate/common/hibernate-commons-annotations/5.0.1.Final/hibernate-commons-annotations-5.0.1.Final.jar:/home/sasha/.m2/repository/org/hibernate/hibernate-entitymanager/5.2.10.Final/hibernate-entitymanager-5.2.10.Final.jar:/home/sasha/.m2/repository/net/bytebuddy/byte-buddy/1.6.6/byte-buddy-1.6.6.jar:/home/sasha/.m2/repository/org/hibernate/hibernate-ehcache/5.2.10.Final/hibernate-ehcache-5.2.10.Final.jar:/home/sasha/.m2/repository/net/sf/ehcache/ehcache/2.10.4/ehcache-2.10.4.jar:/home/sasha/.m2/repository/com/mchange/c3p0/0.9.5.2/c3p0-0.9.5.2.jar:/home/sasha/.m2/repository/com/mchange/mchange-commons-java/0.2.11/mchange-commons-java-0.2.11.jar:/home/sasha/.m2/repository/org/postgresql/postgresql/42.0.0/postgresql-42.0.0.jar ua.alekstar.moneysaver.MoneysaverApplication

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.3.RELEASE)

2017-05-13 21:15:20.109  INFO 9745 --- [           main] u.a.moneysaver.MoneysaverApplication     : Starting MoneysaverApplication on sasha-pc with PID 9745 (/home/sasha/Documents/development/moneysaver/target/classes started by sasha in /home/sasha/Documents/development/moneysaver)
2017-05-13 21:15:20.112  INFO 9745 --- [           main] u.a.moneysaver.MoneysaverApplication     : No active profile set, falling back to default profiles: default
2017-05-13 21:15:20.165  INFO 9745 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@319b92f3: startup date [Sat May 13 21:15:20 EEST 2017]; root of context hierarchy
2017-05-13 21:15:22.043  INFO 9745 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-05-13 21:15:22.053  INFO 9745 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-05-13 21:15:22.054  INFO 9745 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-05-13 21:15:22.147  INFO 9745 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-05-13 21:15:22.147  INFO 9745 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1985 ms
2017-05-13 21:15:22.259  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-05-13 21:15:22.262  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-05-13 21:15:22.263  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-05-13 21:15:22.263  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-05-13 21:15:22.263  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-05-13 21:15:22.311  INFO 9745 --- [g-Init-Reporter] com.mchange.v2.log.MLog                  : MLog clients using slf4j logging.
2017-05-13 21:15:22.394  INFO 9745 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-05-13 21:15:22.404  INFO 9745 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2017-05-13 21:15:22.468  INFO 9745 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.10.Final}
2017-05-13 21:15:22.470  INFO 9745 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-05-13 21:15:22.503  INFO 9745 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-05-13 21:15:22.628  INFO 9745 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL94Dialect
2017-05-13 21:15:22.737  INFO 9745 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2017-05-13 21:15:22.739  INFO 9745 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@1e008f36
2017-05-13 21:15:23.195  INFO 9745 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-05-13 21:15:23.645  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@319b92f3: startup date [Sat May 13 21:15:20 EEST 2017]; root of context hierarchy
2017-05-13 21:15:23.697  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[POST]}" onto public void ua.alekstar.moneysaver.rest.AccountJsonRestController.post(ua.alekstar.moneysaver.rest.account.Account)
2017-05-13 21:15:23.698  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[GET]}" onto public ua.alekstar.moneysaver.rest.account.Accounts ua.alekstar.moneysaver.rest.AccountJsonRestController.get(java.lang.Long)
2017-05-13 21:15:23.698  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[PUT]}" onto public void ua.alekstar.moneysaver.rest.AccountJsonRestController.put(ua.alekstar.moneysaver.rest.account.Account)
2017-05-13 21:15:23.698  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[DELETE]}" onto public void ua.alekstar.moneysaver.rest.AccountJsonRestController.delete(java.lang.Long)
2017-05-13 21:15:23.700  WARN 9745 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map '/json/currency' method
public void ua.alekstar.moneysaver.rest.CurrencyJsonRestController.post(ua.alekstar.moneysaver.rest.currency.Currency)
to {[],methods=[POST]}: There is already '/json/account' bean method
public void ua.alekstar.moneysaver.rest.AccountJsonRestController.post(ua.alekstar.moneysaver.rest.account.Account) mapped.
2017-05-13 21:15:23.701  INFO 9745 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-05-13 21:15:23.703  INFO 9745 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2017-05-13 21:15:23.716  INFO 9745 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-05-13 21:15:23.722 ERROR 9745 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map '/json/currency' method
public void ua.alekstar.moneysaver.rest.CurrencyJsonRestController.post(ua.alekstar.moneysaver.rest.currency.Currency)
to {[],methods=[POST]}: There is already '/json/account' bean method
public void ua.alekstar.moneysaver.rest.AccountJsonRestController.post(ua.alekstar.moneysaver.rest.account.Account) mapped.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at ua.alekstar.moneysaver.MoneysaverApplication.main(MoneysaverApplication.java:10) [classes/:na]
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map '/json/currency' method
public void ua.alekstar.moneysaver.rest.CurrencyJsonRestController.post(ua.alekstar.moneysaver.rest.currency.Currency)
to {[],methods=[POST]}: There is already '/json/account' bean method
public void ua.alekstar.moneysaver.rest.AccountJsonRestController.post(ua.alekstar.moneysaver.rest.account.Account) mapped.
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:576) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:540) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:264) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:250) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:214) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:184) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:127) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    ... 16 common frames omitted

Process finished with exit code 1
```

After I remove one of the REST controllers the application runs successfully. What should I do to solve this issue?

答:
Since this answer appears on top of google searches, and my problem was a bit different, I am posting my solution:

I got the Spring Boot Ambiguous mapping. Cannot map method error.

The problem:

I had two controller methods with same @RequestMapping which were conflicting. Copy/paste mistake :)

The fix:

Change to appropriate @RequestMapping.

Body:
I have 2 REST controllers in my Spring Boot application with simple CRUD operations.

REST controller, that is mapped to "/json/currency"

package ua.alekstar.moneysaver.rest;

import org.springframework.web.bind.annotation.*;
import ua.alekstar.moneysaver.rest.currency.Currencies;
import ua.alekstar.moneysaver.rest.currency.Currency;
import ua.alekstar.moneysaver.service.CurrencyService;

import java.util.Collections;

@RestController("/json/currency")
public class CurrencyJsonRestController {

    private final CurrencyService currencyService;

    public CurrencyJsonRestController(CurrencyService currencyService) {
        this.currencyService = currencyService;
    }

    @GetMapping
    @ResponseBody
    public Currencies get(@RequestParam(required = false) Long id) {
        if (id == null) {
            return readAll();
        }
        return read(id);
    }

    private Currencies read(Long id) {
        return new Currencies(Collections.singletonList(currencyService.read(id)));
    }

    private Currencies readAll() {
        return new Currencies(currencyService.readAll());
    }

    @PostMapping
    public void post(@RequestBody Currency currency) {
        currencyService.create(currency.toEntity());
    }

    @PutMapping
    public void put(@RequestBody Currency currency) {
        currencyService.update(currency.toEntity());
    }

    @DeleteMapping
    public void delete(@RequestParam Long id) {
        currencyService.delete(id);
    }
}

and REST controller, that is mapped to "/json/account"

package ua.alekstar.moneysaver.rest;

import org.springframework.web.bind.annotation.*;
import ua.alekstar.moneysaver.dao.entities.Currency;
import ua.alekstar.moneysaver.rest.account.Account;
import ua.alekstar.moneysaver.rest.account.Accounts;
import ua.alekstar.moneysaver.service.AccountService;
import ua.alekstar.moneysaver.service.CurrencyService;

import java.util.Collections;

@RestController("/json/account")
public class AccountJsonRestController {

    private final AccountService accountService;
    private final CurrencyService currencyService;

    public AccountJsonRestController(AccountService accountService, CurrencyService currencyService) {
        this.accountService = accountService;
        this.currencyService = currencyService;
    }

    @GetMapping
    @ResponseBody
    public Accounts get(@RequestParam(required = false) Long id) {
        if (id == null) {
            return readAll();
        }
        return read(id);
    }

    private Accounts read(Long id) {
        return new Accounts(Collections.singletonList(accountService.read(id)));
    }

    private Accounts readAll() {
        return new Accounts(accountService.readAll());
    }

    @PostMapping
    public void post(@RequestBody Account account) {
        accountService.create(toEntity(account));
    }

    private ua.alekstar.moneysaver.dao.entities.Account toEntity(Account account) {
        final Currency currency = currencyService.readByIsoCode(account.getCurrency());
        return new ua.alekstar.moneysaver.dao.entities.Account(account.getId(), account.getName(), currency);
    }

    @PutMapping
    public void put(@RequestBody Account account) {
        accountService.update(toEntity(account));
    }

    @DeleteMapping
    public void delete(@RequestParam Long id) {
        accountService.delete(id);
    }

}

While I start my application I have an exception and I do not understand why it happens.

/usr/lib/jvm/java-8-oracle/bin/java -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:/home/sasha/Applications/idea-IU-171.3780.107/lib/idea_rt.jar=32820:/home/sasha/Applications/idea-IU-171.3780.107/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/home/sasha/Documents/development/moneysaver/target/classes:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/1.5.3.RELEASE/spring-boot-starter-data-jpa-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter/1.5.3.RELEASE/spring-boot-starter-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot/1.5.3.RELEASE/spring-boot-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.5.3.RELEASE/spring-boot-autoconfigure-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.5.3.RELEASE/spring-boot-starter-logging-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar:/home/sasha/.m2/repository/ch/qos/logback/logback-core/1.1.11/logback-core-1.1.11.jar:/home/sasha/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar:/home/sasha/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.25/log4j-over-slf4j-1.7.25.jar:/home/sasha/.m2/repository/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-aop/1.5.3.RELEASE/spring-boot-starter-aop-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-aop/4.3.8.RELEASE/spring-aop-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/aspectj/aspectjweaver/1.8.10/aspectjweaver-1.8.10.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/1.5.3.RELEASE/spring-boot-starter-jdbc-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/apache/tomcat/tomcat-jdbc/8.5.14/tomcat-jdbc-8.5.14.jar:/home/sasha/.m2/repository/org/apache/tomcat/tomcat-juli/8.5.14/tomcat-juli-8.5.14.jar:/home/sasha/.m2/repository/org/springframework/spring-jdbc/4.3.8.RELEASE/spring-jdbc-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/javax/transaction/javax.transaction-api/1.2/javax.transaction-api-1.2.jar:/home/sasha/.m2/repository/org/springframework/data/spring-data-jpa/1.11.3.RELEASE/spring-data-jpa-1.11.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/data/spring-data-commons/1.13.3.RELEASE/spring-data-commons-1.13.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-orm/4.3.8.RELEASE/spring-orm-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-context/4.3.8.RELEASE/spring-context-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-tx/4.3.8.RELEASE/spring-tx-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-beans/4.3.8.RELEASE/spring-beans-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/home/sasha/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.25/jcl-over-slf4j-1.7.25.jar:/home/sasha/.m2/repository/org/springframework/spring-aspects/4.3.8.RELEASE/spring-aspects-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.5.3.RELEASE/spring-boot-starter-web-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.5.3.RELEASE/spring-boot-starter-tomcat-1.5.3.RELEASE.jar:/home/sasha/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.14/tomcat-embed-core-8.5.14.jar:/home/sasha/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.5.14/tomcat-embed-el-8.5.14.jar:/home/sasha/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.14/tomcat-embed-websocket-8.5.14.jar:/home/sasha/.m2/repository/org/hibernate/hibernate-validator/5.3.5.Final/hibernate-validator-5.3.5.Final.jar:/home/sasha/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar:/home/sasha/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.8.8/jackson-databind-2.8.8.jar:/home/sasha/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar:/home/sasha/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.8/jackson-core-2.8.8.jar:/home/sasha/.m2/repository/org/springframework/spring-web/4.3.8.RELEASE/spring-web-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-webmvc/4.3.8.RELEASE/spring-webmvc-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-expression/4.3.8.RELEASE/spring-expression-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.jar:/home/sasha/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.1.Final/hibernate-jpa-2.0-api-1.0.1.Final.jar:/home/sasha/.m2/repository/org/hibernate/hibernate-core/5.2.10.Final/hibernate-core-5.2.10.Final.jar:/home/sasha/.m2/repository/org/jboss/logging/jboss-logging/3.3.1.Final/jboss-logging-3.3.1.Final.jar:/home/sasha/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar:/home/sasha/.m2/repository/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar:/home/sasha/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/home/sasha/.m2/repository/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.0.1.Final/jboss-transaction-api_1.2_spec-1.0.1.Final.jar:/home/sasha/.m2/repository/org/jboss/jandex/2.0.3.Final/jandex-2.0.3.Final.jar:/home/sasha/.m2/repository/com/fasterxml/classmate/1.3.3/classmate-1.3.3.jar:/home/sasha/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/home/sasha/.m2/repository/org/hibernate/common/hibernate-commons-annotations/5.0.1.Final/hibernate-commons-annotations-5.0.1.Final.jar:/home/sasha/.m2/repository/org/hibernate/hibernate-entitymanager/5.2.10.Final/hibernate-entitymanager-5.2.10.Final.jar:/home/sasha/.m2/repository/net/bytebuddy/byte-buddy/1.6.6/byte-buddy-1.6.6.jar:/home/sasha/.m2/repository/org/hibernate/hibernate-ehcache/5.2.10.Final/hibernate-ehcache-5.2.10.Final.jar:/home/sasha/.m2/repository/net/sf/ehcache/ehcache/2.10.4/ehcache-2.10.4.jar:/home/sasha/.m2/repository/com/mchange/c3p0/0.9.5.2/c3p0-0.9.5.2.jar:/home/sasha/.m2/repository/com/mchange/mchange-commons-java/0.2.11/mchange-commons-java-0.2.11.jar:/home/sasha/.m2/repository/org/postgresql/postgresql/42.0.0/postgresql-42.0.0.jar ua.alekstar.moneysaver.MoneysaverApplication

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.3.RELEASE)

2017-05-13 21:15:20.109  INFO 9745 --- [           main] u.a.moneysaver.MoneysaverApplication     : Starting MoneysaverApplication on sasha-pc with PID 9745 (/home/sasha/Documents/development/moneysaver/target/classes started by sasha in /home/sasha/Documents/development/moneysaver)
2017-05-13 21:15:20.112  INFO 9745 --- [           main] u.a.moneysaver.MoneysaverApplication     : No active profile set, falling back to default profiles: default
2017-05-13 21:15:20.165  INFO 9745 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@319b92f3: startup date [Sat May 13 21:15:20 EEST 2017]; root of context hierarchy
2017-05-13 21:15:22.043  INFO 9745 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-05-13 21:15:22.053  INFO 9745 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-05-13 21:15:22.054  INFO 9745 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-05-13 21:15:22.147  INFO 9745 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-05-13 21:15:22.147  INFO 9745 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1985 ms
2017-05-13 21:15:22.259  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-05-13 21:15:22.262  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-05-13 21:15:22.263  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-05-13 21:15:22.263  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-05-13 21:15:22.263  INFO 9745 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-05-13 21:15:22.311  INFO 9745 --- [g-Init-Reporter] com.mchange.v2.log.MLog                  : MLog clients using slf4j logging.
2017-05-13 21:15:22.394  INFO 9745 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-05-13 21:15:22.404  INFO 9745 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2017-05-13 21:15:22.468  INFO 9745 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.10.Final}
2017-05-13 21:15:22.470  INFO 9745 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-05-13 21:15:22.503  INFO 9745 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-05-13 21:15:22.628  INFO 9745 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL94Dialect
2017-05-13 21:15:22.737  INFO 9745 --- [           main] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2017-05-13 21:15:22.739  INFO 9745 --- [           main] org.hibernate.type.BasicTypeRegistry     : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@1e008f36
2017-05-13 21:15:23.195  INFO 9745 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-05-13 21:15:23.645  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@319b92f3: startup date [Sat May 13 21:15:20 EEST 2017]; root of context hierarchy
2017-05-13 21:15:23.697  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[POST]}" onto public void ua.alekstar.moneysaver.rest.AccountJsonRestController.post(ua.alekstar.moneysaver.rest.account.Account)
2017-05-13 21:15:23.698  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[GET]}" onto public ua.alekstar.moneysaver.rest.account.Accounts ua.alekstar.moneysaver.rest.AccountJsonRestController.get(java.lang.Long)
2017-05-13 21:15:23.698  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[PUT]}" onto public void ua.alekstar.moneysaver.rest.AccountJsonRestController.put(ua.alekstar.moneysaver.rest.account.Account)
2017-05-13 21:15:23.698  INFO 9745 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[DELETE]}" onto public void ua.alekstar.moneysaver.rest.AccountJsonRestController.delete(java.lang.Long)
2017-05-13 21:15:23.700  WARN 9745 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map '/json/currency' method
public void ua.alekstar.moneysaver.rest.CurrencyJsonRestController.post(ua.alekstar.moneysaver.rest.currency.Currency)
to {[],methods=[POST]}: There is already '/json/account' bean method
public void ua.alekstar.moneysaver.rest.AccountJsonRestController.post(ua.alekstar.moneysaver.rest.account.Account) mapped.
2017-05-13 21:15:23.701  INFO 9745 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-05-13 21:15:23.703  INFO 9745 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2017-05-13 21:15:23.716  INFO 9745 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-05-13 21:15:23.722 ERROR 9745 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map '/json/currency' method
public void ua.alekstar.moneysaver.rest.CurrencyJsonRestController.post(ua.alekstar.moneysaver.rest.currency.Currency)
to {[],methods=[POST]}: There is already '/json/account' bean method
public void ua.alekstar.moneysaver.rest.AccountJsonRestController.post(ua.alekstar.moneysaver.rest.account.Account) mapped.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at ua.alekstar.moneysaver.MoneysaverApplication.main(MoneysaverApplication.java:10) [classes/:na]
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map '/json/currency' method
public void ua.alekstar.moneysaver.rest.CurrencyJsonRestController.post(ua.alekstar.moneysaver.rest.currency.Currency)
to {[],methods=[POST]}: There is already '/json/account' bean method
public void ua.alekstar.moneysaver.rest.AccountJsonRestController.post(ua.alekstar.moneysaver.rest.account.Account) mapped.
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:576) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:540) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:264) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:250) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:214) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:184) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:127) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    ... 16 common frames omitted

Process finished with exit code 1

After I remove one of the REST controllers the application runs successfully. What should I do to solve this issue?


问:
Calculate the values of input where each input has different prices. Any shorter code for this?(javascript only)

The code below is working fine but what if there are 100 inputs? any shorter way to do this?

function checkTotal() {
  var a = document.getElementById("sandwich").value;
  var b = document.getElementById("burger").value;
  var c = document.getElementById("cake").value;
  var d = document.getElementById("coffee").value;
  document.getElementById("total").value = parseInt(a) * 10 + parseInt(b) * 5 + parseInt(c) * 15 + parseInt(d) * 20;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><form role="form" name="listForm">
  <label>Sandwich</label>
  <input type="number" id="sandwich" value="0" onkeyup="checkTotal()"><br>

  <label>Burger</label>
  <input type="number" id="burger" value="0" onkeyup="checkTotal()"><br>

  <label>Cake</label>
  <input type="number" id="cake" value="0" onkeyup="checkTotal()"><br>

  <label>Coffee</label>
  <input type="number" id="coffee" value="0" onkeyup="checkTotal()"><br> Total: <input type="text" size="2" name="total" id="total" value="0" />
</form></code>```

    1) Here each input article has a different price.
    2) The value of the input should be mutiply with its price given(Eg. if the sandwich has a price:30, and user inputs value 2 it should calculte the total=price*input value.)
    3) i have my code which is working fine but is the above code is the right way to do?
    4) what if there are 100 of article inputs. is there shorter code or should i create variable for each one?

答:
Another way to try is to give your elements a class and some data attributes that can be retrieved by JavaScript using dataset. You can then use them to make your calculations. That way you get rid of ids and you just have to change the HTML code to add a new element.

function checkTotal() {
  var total = 0,
      foods = document.querySelectorAll('.food');

  for (var i = 0; i < foods.length; i++) {
    var food = foods[i],
        name = food.dataset.item,
        price = parseInt(food.dataset.price),
        howMany = parseInt(food.value);

    console.log(howMany, name, 'costs', (howMany * price));

    total += howMany * price;
  }

  document.getElementById('total').value = total;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><form role="form" name="listForm">
  <label>Sandwich</label>
  <input class="food" data-item="sandwich" data-price="30" type="number" value="0" onBlur="checkTotal()"><br>

  <label>Burger</label>
  <input class="food" data-item="burger" data-price="10" type="number" value="0" onBlur="checkTotal()"><br>

  <label>Cake</label>
  <input class="food" data-item="cake" data-price="5" type="number" value="0" onBlur="checkTotal()"><br>

  <label>Coffee</label>
  <input class="food" data-item="coffee" data-price="15" type="number" value="0" onBlur="checkTotal()"><br>
  Total: <input type="text" size="2" name="total" id="total" value="0" />
</form></code>```

As a side note, you should give a try on Angular or Knockout which can help you to achieve those operations.

Body:
The code below is working fine but what if there are 100 inputs? any shorter way to do this?

function checkTotal() {
  var a = document.getElementById("sandwich").value;
  var b = document.getElementById("burger").value;
  var c = document.getElementById("cake").value;
  var d = document.getElementById("coffee").value;
  document.getElementById("total").value = parseInt(a) * 10 + parseInt(b) * 5 + parseInt(c) * 15 + parseInt(d) * 20;
}

<form role="form" name="listForm">
  Sandwich
  <input type="number" id="sandwich" value="0" onkeyup="checkTotal()">

  Burger
  <input type="number" id="burger" value="0" onkeyup="checkTotal()">

  Cake
  <input type="number" id="cake" value="0" onkeyup="checkTotal()">

  Coffee
  <input type="number" id="coffee" value="0" onkeyup="checkTotal()">
 Total: <input type="text" size="2" name="total" id="total" value="0" />
</form>

    1) Here each input article has a different price.
    2) The value of the input should be mutiply with its price given(Eg. if the sandwich has a price:30, and user inputs value 2 it should calculte the total=price*input value.)
    3) i have my code which is working fine but is the above code is the right way to do?
    4) what if there are 100 of article inputs. is there shorter code or should i create variable for each one?

Body:
Another way to try is to give your elements a class and some data attributes that can be retrieved by JavaScript using dataset. You can then use them to make your calculations. That way you get rid of ids and you just have to change the HTML code to add a new element.

function checkTotal() {
  var total = 0,
      foods = document.querySelectorAll('.food');

  for (var i = 0; i < foods.length; i++) {
    var food = foods[i],
        name = food.dataset.item,
        price = parseInt(food.dataset.price),
        howMany = parseInt(food.value);

    console.log(howMany, name, 'costs', (howMany * price));

    total += howMany * price;
  }

  document.getElementById('total').value = total;
}

<form role="form" name="listForm">
  <label>Sandwich</label>
  <input class="food" data-item="sandwich" data-price="30" type="number" value="0" onBlur="checkTotal()"><br>

  <label>Burger</label>
  <input class="food" data-item="burger" data-price="10" type="number" value="0" onBlur="checkTotal()"><br>

  <label>Cake</label>
  <input class="food" data-item="cake" data-price="5" type="number" value="0" onBlur="checkTotal()"><br>

  <label>Coffee</label>
  <input class="food" data-item="coffee" data-price="15" type="number" value="0" onBlur="checkTotal()"><br>
  Total: <input type="text" size="2" name="total" id="total" value="0" />
</form>

As a side note, you should give a try on Angular or Knockout which can help you to achieve those operations.


问:
Quick successful exit from C++ with lots of objects allocated
I'm looking for a way to quickly exit a C++ that has allocated a lot of structures in memory using C++ classes.  The program finishes correctly, but after the final "return" in the program, all of the auto-destructors kick in.  The problem is the program has allocated about 15GB of memory through lots of C++ class structures, and this auto-destruct process takes about 1 more hour itself to complete as it walks through all of the structures - even though I don't care about the results.  The program only took 1 hour to complete the task up to this point.  I would like to just return to the OS and let it do its normal wholesale process allocation deletion - which is very quick.  I've been doing this by manually killing the process during the cleanup stage - but am looking for a better programic solution.

I would like to return a success to the OS, but don't care to keep any of the memory content.  The program does perform a lot of dynamic allocation/deallocation during the normal processing, so it's not just simple heap management.

Any opinions?

答: If the 15 GB of memory is being allocated to a reasonably small number of classes, you could override operator delete for those classes. Just pass the call to the standard delete, but set up a global flag that, if set, will make the call to delete a no-op. Or, if the logic of your program is such that these objects are not deleted in the normal course of building your data structures, you could simply ignore delete in all cases for these classes.</p>


问:
Segment a region in Depth Image of Microsoft Kinect using Open CV Python
I am working on Hand Segmentation using Microsoft Kinect Depth Stream. By doing some thresholding I was able to separate body from background, based on depth information provided by MS Kinect Sensor now I want is to segment hands. Any suggestions how can I segment Hands. Below is a screen shot of my depth Image.
I am using  Open CV in Python. To access Kinect Sensor streams, I am using PyKinect from Microsoft.

答:
What you need is a semantic segmentation algorithm. Random decision forests gave fantastic results. Check the work published by Haggag et al. It is built on top of the work done by Shotton et al and Buys et al.

If you want to use deep learning, check the work done by Abubakr et al.The base papers are published by Shotton et al. and Buys et al. Shoton's work is the one that founded Kinect.

[1] Shotton et al., "Efficient human pose estimation from single depth images,” IEEE Transactions on Pattern Analysis and Machine Intelligence, 2013.

[2] Buys et al., "An adaptable system for RGB-D based human body detection and pose estimation,” Journal of Visual Communication and Image Representation, 2014.

Haggag et al. and Abobakr et al. built on these papers to produce the following using random forests.

[3] Abobakr et al., "A Skeleton-Free Fall Detection System from Depth Images Using Random Decision Forest," IEEE Systems Journal, 2018.

[4] Haggag et al., "An adaptable system for RGB-D based human body detection and pose estimation: Incorporating attached props," IEEE International Conference on Systems, Man, and Cybernetics (SMC), 2016.

[5] Haggag et al., "Semantic body parts segmentation for quadrupedal animals," IEEE International Conference on Systems, Man, and Cybernetics (SMC), 2016.

For better voting scheme and nominal label/decision fusion of the label maps produced by the random trees, check my paper below.

[6] Hossny et al., "Decision Fusion of Labelled Images with Local Majority Filter,” Electronics Letters, 2017.

Abobakr et al., have then incorporated deep learning.

[7] Abobakr et al., "Body joints regression using deep convolutional neural networks," IEEE International Conference on Systems, Man, and Cybernetics (SMC), 2016.

[8] Abobakr et al., "RGB-D human posture analysis for ergonomie studies using deep convolutional neural network," IEEE International Conference on Systems, Man, and Cybernetics (SMC), 2017.

[9] Nahavandi et al., "A skeleton-free body surface area estimation from depth images using deep neural networks," IEEE International Conference on Systems, Man, and Cybernetics (SMC), 2017.