问:
How can I use lazyload in Angular4?
I try to do

{ path: 'options', loadChildren: 'app/options/options.module#OptionsModule'}

every file module,html,js load complete

I can route normaly

but I click link route in loadChildren not thing change

I use hashbang(#) in root route

I can't not write this RouterModule.forChild(routes,{ useHash: true })

if you not use lazy load Angular will load all of page and component for 1 route

Question?

1. How necessary to set
ChildRouter Hashbang like this

RouterModule.forChild(routes)

Because RootRouter use hashbang(#) like this

RouterModule.forRoot(routes,{ useHash: true }) ?

2.you can show me code Angular4.X in Lazyload Route loadChildren ?

------------------------ Please Help Me -----------------------------

I use this : https://github.com/varishero/laravel5.4-angular4-ts2

答:
Suppose you have a module named TestModule in test.module.ts locates at app/test/, in routing to load it:</p>

```<code>const routes: Routes = [
    { path: 'test', loadChildren: 'app/test/test.module#TestModule'},
];
</code>```

Title: How can I use lazyload in Angular4?

Body:
Suppose you have a module named TestModule in test.module.ts locates at app/test/, in routing to load it:

const routes: Routes = [
    { path: 'test', loadChildren: 'app/test/test.module#TestModule'},
];


来源: stackexchange

问:
TimeOut for Websocket Connection In Scala
I have a websocket connection from client to api service, and then from API service to other Services.
Now by default the connection timeout(i.e when no message/communication is done on web socket connection) is 1 min and I found settings to increase it , i.e using akka.http.client.idle-timeout = 300s and
akka.http.server.idle-timeout = 300s .

But in my case these setting works on local, the timeout incresed(i.e while running the services locally on my pc), But not when I deploy the services on EC2 making docker images.

So please can anyone tell me why its behaving like this?

答:
This looks much more like a Docker configuration issue rather than an akka problem. You should debug the configuration of your container in two ways:

Log on the EC2 instance and inspect the environment parameter using docker inspect <containerid>

Forcing Akka to print out the configuration

You can either set the following parameter in your application.conf

```<code>   akka {
      log-config-on-start = "on"
    }
</code>```

Or explicitly invoke by code

```<code>myConfig.root().render()
</code>```

ContentLicense: CC BY-SA 3.0

Body:
This looks much more like a Docker configuration issue rather than an akka problem. You should debug the configuration of your container in two ways:

Log on the EC2 instance and inspect the environment parameter using docker inspect <containerid>

Forcing Akka to print out the configuration

You can either set the following parameter in your application.conf

   akka {
      log-config-on-start = "on"
    }

Or explicitly invoke by code

myConfig.root().render()


问:
Get unique data about clicked button in Phonegap
I have my simple Phonegap app, which is based on tabbed layout. On one of these tabs I have list of tags (more than one). All of these have buttons to edit and delete. Its like this:

```<code>        <div class="tag-buttons" uid="TAG_ID">
            <button class="edit-tag btn btn-default btn-sm">Edit</button>
            <button id="aaa" class="remove-tag btn btn-danger btn-sm" onclick="removeTag()">Remove</button>
        </div>
</code>```

Now I want do handle this removeTag() function. So I have in my JS file this function:

```<code>function removeTag()
{
    //controller.removeTag($(this).parent().attr("uid"));
    console.log($(this));
}
</code>```

Console.log and commented line are only samples. I want to know which button was clicked (I need uid value). All of buttons have this same class. $(this) is returning Window object.
Any ideas?

答:
I had made stupid error. Now everything is working.
I had to change onclick="removeTag()" to onclick="removeTag(this)" and then in JS function was quite good. I changed function declaration to use additional argument like this:

```<code>function removeTag(button)
{
    var id = $(button).parent().parent().attr("uid");
    controller.popTag(id);
}
</code>```

Body:
I have my simple Phonegap app, which is based on tabbed layout. On one of these tabs I have list of tags (more than one). All of these have buttons to edit and delete. Its like this:

            <button class="edit-tag btn btn-default btn-sm">Edit</button>
            <button id="aaa" class="remove-tag btn btn-danger btn-sm" onclick="removeTag()">Remove</button>

Now I want do handle this removeTag() function. So I have in my JS file this function:

function removeTag()
{
    //controller.removeTag($(this).parent().attr("uid"));
    console.log($(this));
}

Console.log and commented line are only samples. I want to know which button was clicked (I need uid value). All of buttons have this same class. $(this) is returning Window object.
Any ideas?

Body:
I had made stupid error. Now everything is working.
I had to change onclick="removeTag()" to onclick="removeTag(this)" and then in JS function was quite good. I changed function declaration to use additional argument like this:

function removeTag(button)
{
    var id = $(button).parent().parent().attr("uid");
    controller.popTag(id);
}


问:
How to modify list entries during for loop?
Now I know that it is not safe to modify the list during an iterative looping. However, suppose I have a list of strings, and I want to strip the strings themselves. Does replacement of mutable values count as modification?

See Scope of python variable in for loop for a related problem: assigning to the iteration variable does not modify the underlying sequence, and also does not impact future iteration.

答:
You can do something like this:

```<code>a = [1,2,3,4,5]
b = [i**2 for i in a]
</code>```

It's called a list comprehension, to make it easier for you to loop inside a list.

ContentLicense: CC BY-SA 4.0

Body:
You can do something like this:

a = [1,2,3,4,5]
b = [i**2 for i in a]

It's called a list comprehension, to make it easier for you to loop inside a list.


问:
System.StackOverflowException when creating instance of class
I am getting a System.StackOverflowException when I create an instance of my Vehicle class. I believe it is happening because I have an object reference to my Car class which inherits from Vehicle, and it is getting stuck an infinite loop.

```<code>Public Class Vehicle
   Public Car As New Car
End Class

Public Class Car
   Inherits Vehicle

   Public Sub doStuff()
      'does stuff
   End Sub
End Class
</code>```

While probably bad practice, I have it structured like this because I need to be able to access doStuff() from another file without having to create an instance of Car, like so:

```<code>'some other file
Public Class Foo
   Private Vehicle As New Vehicle
   Vehicle.Car.doStuff() 'this is what I am trying to accomplish
End Class
</code>```

Is there another way I can accomplish this?

EDIT: Since there seems to be a little bit of confusion, I want to clarify that I have multiple classes that inherit from Vehicle (Car, Truck, Bike, etc.). All of these classes have their own unique methods but all need to use some of the methods and properties of Vehicle. Using virtual isn't exactly what I am looking for since I am not needing to override any methods.

答:
Okay, I think this might be a misunderstanding of why you want to derive classes.  Let me give you an example using your two classes:

```<code>Public Class Vehicle
    Public Sub DoVehicleStuff()
        ' code here
    End Sub
    Public Overridable Sub OverridableVehicleStuff()
        'code here
    End Sub
End Class

Public Class Car
    Inherits Vehicle

    Public Sub DoCarStuff()
        'code here
    End Sub
    Public Overrides Sub OverridableVehicleStuff()
        'code here
    End Sub
End Class
</code>```

Okay, Vehicle has two functions - and one of them is 'overridable', which means it's there, but derived classes can override it.  Then, Car inherits from Vehicle - which means it gets the same DoVehicleStuff() and OverridableVehicleStuff().  But then it adds an additional function DoCarStuff() and replaces the OverridableVehicleStuff with its own version of the function.

Putting it all together, we can use the classes like this:

```<code>Dim myVehicle As Vehicle = New Vehicle()
myVehicle.DoVehicleStuff()
myVehicle.OverridableVehicleStuff() ' does the VEHICLE version of the function
'this will not compile: myVehicle.DoCarStuff() - because vehicles do not have that function.  It is in the car sub-class.

Dim myCarStoredInVehicle As Vehicle = New Car()
myCarStoredInVehicle.DoVehicleStuff() 'I can still use this function - because Car inherited it
myCarStoredInVehicle.OverridableVehicleStuff() 'this will do the CAR version of the function.
'this will not compile: myCarStoredInVehicle.DoCarStuff()

Dim myCar As Car = New Car()
myCar.DoVehicleStuff() 'I can still call this function.
myCar.DoCarStuff() 'and I can do the DoCarStuff() function, because the variable is a Car.
</code>```

So to answer your question: is doStuff() something that all vehicles need, or just cars?  If it's something that all vehicles need to do in some manner or another, you need to write a overridable (or abstract) function.  If it's something that only Cars use, then you can't use a Vehicle class instance for what you want.  You want one of these options:

Declare your variable as a Car.

Declare your variable as a Vehicle, but instantiate it as a New
Car().  And then cast the variable as a (Car) when you need to use
DoStuff().

EDIT: Whoops, the OP is asking about VB, not C#.  Edited the code as appropriate.

Body:
I am getting a System.StackOverflowException when I create an instance of my Vehicle class. I believe it is happening because I have an object reference to my Car class which inherits from Vehicle, and it is getting stuck an infinite loop.

Public Class Vehicle
   Public Car As New Car
End Class

Public Class Car
   Inherits Vehicle

   Public Sub doStuff()
      'does stuff
   End Sub
End Class

While probably bad practice, I have it structured like this because I need to be able to access doStuff() from another file without having to create an instance of Car, like so:

'some other file
Public Class Foo
   Private Vehicle As New Vehicle
   Vehicle.Car.doStuff() 'this is what I am trying to accomplish
End Class

Is there another way I can accomplish this?

EDIT: Since there seems to be a little bit of confusion, I want to clarify that I have multiple classes that inherit from Vehicle (Car, Truck, Bike, etc.). All of these classes have their own unique methods but all need to use some of the methods and properties of Vehicle. Using virtual isn't exactly what I am looking for since I am not needing to override any methods.

Body:
Okay, I think this might be a misunderstanding of why you want to derive classes.  Let me give you an example using your two classes:

Public Class Vehicle
    Public Sub DoVehicleStuff()
        ' code here
    End Sub
    Public Overridable Sub OverridableVehicleStuff()
        'code here
    End Sub
End Class

Public Class Car
    Inherits Vehicle

    Public Sub DoCarStuff()
        'code here
    End Sub
    Public Overrides Sub OverridableVehicleStuff()
        'code here
    End Sub
End Class

Okay, Vehicle has two functions - and one of them is 'overridable', which means it's there, but derived classes can override it.  Then, Car inherits from Vehicle - which means it gets the same DoVehicleStuff() and OverridableVehicleStuff().  But then it adds an additional function DoCarStuff() and replaces the OverridableVehicleStuff with its own version of the function.

Putting it all together, we can use the classes like this:

Dim myVehicle As Vehicle = New Vehicle()
myVehicle.DoVehicleStuff()
myVehicle.OverridableVehicleStuff() ' does the VEHICLE version of the function
'this will not compile: myVehicle.DoCarStuff() - because vehicles do not have that function.  It is in the car sub-class.

Dim myCarStoredInVehicle As Vehicle = New Car()
myCarStoredInVehicle.DoVehicleStuff() 'I can still use this function - because Car inherited it
myCarStoredInVehicle.OverridableVehicleStuff() 'this will do the CAR version of the function.
'this will not compile: myCarStoredInVehicle.DoCarStuff()

Dim myCar As Car = New Car()
myCar.DoVehicleStuff() 'I can still call this function.
myCar.DoCarStuff() 'and I can do the DoCarStuff() function, because the variable is a Car.

So to answer your question: is doStuff() something that all vehicles need, or just cars?  If it's something that all vehicles need to do in some manner or another, you need to write a overridable (or abstract) function.  If it's something that only Cars use, then you can't use a Vehicle class instance for what you want.  You want one of these options:

Declare your variable as a Car.

Declare your variable as a Vehicle, but instantiate it as a New
Car().  And then cast the variable as a (Car) when you need to use
DoStuff().

EDIT: Whoops, the OP is asking about VB, not C#.  Edited the code as appropriate.


问:
Remove row from database if image not on server
I have a mysql database with a table in the following format:

ID: 1

Date: 2010-12-19

Image: 5d61240f-7aca-d34b-19-12-10-15-36.jpg

Caption: Merry Xmas

I want to create a php script which checks through each row in this table and checks that the image is present in a gallery folder on my server. If the image is not in the gallery folder then I want to delete this row from my database. Some pointers on how to go about doing this would be very much appreciated.

Thanks!

答:
try

```<code><?php

    define ("GALLERY_ROOT", "/path/to/gallery/" );

    $mysqli = new MySQLi ($host, $username, $password, $db);

    $result = $mysqli -> query ("
        SELECT
            id,
            image
        FROM
            table
    ");

    if ( $result ){
        while ($row = $result->fetch_assoc()) {
            if ( !is_file (GALLERY_ROOT . $row['image'] ) ){
                $mysqli -> query ("
                    DELETE FROM
                        table
                    WHERE
                        id = '" . $row['id'] . "'
                    LIMIT 1
                ");

                print "Deleted " . $row['id'] . "<br />";
            }
        }

        $result -> free();
    }

    $mysqli -> close();

    print "Congratz!! All invalid rows has been deleted!";
?>
</code>```

That was a quick one, i didn't try running it actually.

Also if you have a lot of rows, then you might want to rethink about selecting all the rows at once. But again get back to me on how it works

ContentLicense: CC BY-SA 2.5

Body:
try

<?php

    define ("GALLERY_ROOT", "/path/to/gallery/" );

    $mysqli = new MySQLi ($host, $username, $password, $db);

    $result = $mysqli -> query ("
        SELECT
            id,
            image
        FROM
            table
    ");

    if ( $result ){
        while ($row = $result->fetch_assoc()) {
            if ( !is_file (GALLERY_ROOT . $row['image'] ) ){
                $mysqli -> query ("
                    DELETE FROM
                        table
                    WHERE
                        id = '" . $row['id'] . "'
                    LIMIT 1
                ");

                print "Deleted " . $row['id'] . "<br />";
            }
        }

        $result -> free();
    }

    $mysqli -> close();

    print "Congratz!! All invalid rows has been deleted!";
?>

That was a quick one, i didn't try running it actually.

Also if you have a lot of rows, then you might want to rethink about selecting all the rows at once. But again get back to me on how it works


问:
How to decode unicode-encoded JSON in PHP with Zend\Json\Json::decode(...)?
I'm writing a client for an API...

```<code>use Zend\Http\Client;
use Zend\Http\Request;
use Zend\Json\Json;
...
$request = new Request();
$request->getHeaders()->addHeaders([
    'Accept-Charset' => 'UTF-8',
    'Accept' => 'application/hal+json',
    'Content-Type' => 'application/hal+json; charset=UTF-8',
]);
$apiAddress = 'http://my.project.tld/categories';
$request->setUri($apiAddress);
$request->setMethod('GET');
$client = new Client();
$response = $client->dispatch($request);
$data = $response->getContent();
</code>```

... and get a unicode encoded JSON like this:

```<code>...{"id":"7","title":"\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0438","short_name":"\u0418\u041b\u041b\u042e\u0421\u0422\u0420\u0410\u0426\u0418\u0418"...
</code>```

First I tried to decode it with json_decode(...). But I didn't find any appropriate method to do this in PHP (without suspect regex based approaches).

Now I'm trying it with Zend\Json\Json::decode(...) and getting following error:

```<code>/var/www/path/to/project/vendor/zendframework/zend-json/src/Json.php:243
Decoding failed: Syntax error
</code>```

How to get a unicode-encoded JSON decoded with Zend\Json?

EDIT

Just notices, that the JSON is broken. It is separated to two parts. The string starts with 1f9e, then the first part, then the string \u043, then the second content part, then 0.

```<code>1f9e <-- What is it?
{"_li...
\u043 <-- What is it?
1a6...
tfoli <-- What is it?
0
</code>```

答:
Use Zend\Json\Decoder component of ZF2. It has a static method called Decoder::decodeUnicodeString() which decodes unicode characters.

Please have a look at the script here.

Hope this would help you!

Body:
I'm writing a client for an API...

use Zend\Http\Client;
use Zend\Http\Request;
use Zend\Json\Json;
...
$request = new Request();
$request->getHeaders()->addHeaders([
    'Accept-Charset' => 'UTF-8',
    'Accept' => 'application/hal+json',
    'Content-Type' => 'application/hal+json; charset=UTF-8',
]);
$apiAddress = 'http://my.project.tld/categories';
$request->setUri($apiAddress);
$request->setMethod('GET');
$client = new Client();
$response = $client->dispatch($request);
$data = $response->getContent();

... and get a unicode encoded JSON like this:

...{"id":"7","title":"\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0438","short_name":"\u0418\u041b\u041b\u042e\u0421\u0422\u0420\u0410\u0426\u0418\u0418"...

First I tried to decode it with json_decode(...). But I didn't find any appropriate method to do this in PHP (without suspect regex based approaches).

Now I'm trying it with Zend\Json\Json::decode(...) and getting following error:

/var/www/path/to/project/vendor/zendframework/zend-json/src/Json.php:243
Decoding failed: Syntax error

How to get a unicode-encoded JSON decoded with Zend\Json?

EDIT

Just notices, that the JSON is broken. It is separated to two parts. The string starts with 1f9e, then the first part, then the string \u043, then the second content part, then 0.

1f9e <-- What is it?
{"_li...
\u043 <-- What is it?
1a6...
tfoli <-- What is it?
0


问:
Expo on iOS is constantly refreshing my React Native app on MacOS, caused by Dropbox / iCloud
I'm building a simple React Native app and using the Expo iOS app to run it. But Expo is constantly refreshing my app, making it unusable / untestable. It refreshes every few seconds, sometimes multiple times a second, when I haven't changed anything. The only times when there is enough of a break between refreshes for me to test out the app is when, in my terminal, the app decides to rebuild (Again, nothing changed) and takes a few seconds to rebuild the bundle.

I set up the app using create-react-native-app and run it with npm start -- I've changed nothing else, besides adding a few components.

I've tried quitting my IDE (Sublime) and changing to a stronger wifi network.

I'm developing on macOS Sierra 10.12.2 and running on an iPhone 6S.

答:
It turns out this happened because my app's code was stored inside a Dropbox folder. (The same applies to iCloud backups.)

I guess that Dropbox's / iCloud's syncing interferes with watchman or other Expo / React Native internals.

I solved the problem by removing the app's directory from my Dropbox folder.


问:
Converting KML to Array in PHP
I've got stuck when i'm trying to convert a *.kml file to array using PHP language.

kml file >> path.kml

code

```<code>    $dom = new \DOMDocument();
    $dom->loadXml($file);
    $xpath = new \DOMXPath($dom);
    $xpath->registerNamespace('kml', 'http://www.opengis.net/kml/2.2');

    $result = array();
    $places = $xpath->evaluate('//kml:Placemark', NULL, FALSE);
    foreach ($places as $place) {
        $coord = $xpath->evaluate('string(kml:LineString/kml:coordinates)',$place, FALSE);
        $i = explode("\n", $coord);
        $result = array(
            'name' => $xpath->evaluate('string(kml:name)', $place, FALSE),
            'coords' => explode("\n", $coord, count($i)
            )
        );
    }

    var_dump($result);
</code>```

the problem is when i'm trying to explode the string using newLine delimeter, and the result is always like this

whereas i want the result like this

could anyone to help me for solve my problem ? Thank You!

答:
'\r\n' (between single quotes) is: - a literal backslash, the letter r, a literal backslash, and the letter n. It isn't a carriage return and a linefeed. Between single quotes, escape sequences are not interpreted.

Other thing: Are you sure that the newline sequence is CRLF? It can be also only LF (rarely only CR).

Whatever, Try with "\r\n" and if it doesn't work with "\n" (between double quotes).

About PHP strings.

Title: Converting KML to Array in PHP

Body:
I've got stuck when i'm trying to convert a *.kml file to array using PHP language.

kml file >> path.kml

code

    $dom = new \DOMDocument();
    $dom->loadXml($file);
    $xpath = new \DOMXPath($dom);
    $xpath->registerNamespace('kml', 'http://www.opengis.net/kml/2.2');

    $result = array();
    $places = $xpath->evaluate('//kml:Placemark', NULL, FALSE);
    foreach ($places as $place) {
        $coord = $xpath->evaluate('string(kml:LineString/kml:coordinates)',$place, FALSE);
        $i = explode("\n", $coord);
        $result = array(
            'name' => $xpath->evaluate('string(kml:name)', $place, FALSE),
            'coords' => explode("\n", $coord, count($i)
            )
        );
    }

    var_dump($result);

the problem is when i'm trying to explode the string using newLine delimeter, and the result is always like this

whereas i want the result like this

could anyone to help me for solve my problem ? Thank You!


问:
Firebase 3.0 createUserWithEmailAndPassword() error handling
Before, with Firebase 2.x, in order to add a New User we just had to call createUser() on a Firebase reference, pass in the email, password and a ValueResultHandler.

Two callbacks were implemented with that ValueResultHandler:

onSuccess(Map<String, Object> result) {}

onError(FirebaseError firebaseError) {}

In onError, it was easy to grab the firebaseError to handle errors.
Like:

```<code>if (firebaseError.getCode() == FirebaseError.EMAIL_TAKEN) {}
</code>```

However now with the Firebase SDK 3.0, things have changed as it is indicated on the Documentation page.

But how do we do error handling then? For example on that case with an email already taken? Thanks.

答:
You can add new methods when you call createUserWithEmailAndPassword.
You should add the method addOnFailureListener. This is a code example:</p>

```<code>mAuth.createUserWithEmailAndPassword(email, password).
            addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                    if (!task.isSuccessful()) {
                        Toast.makeText(this, R.string.msg_error_auth,
                                Toast.LENGTH_SHORT).show();
                    }
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                   // Here you get the error type
                   Log.d(TAG + " - On Failure", e.getMessage());
            }
    });
</code>```

Body:
Before, with Firebase 2.x, in order to add a New User we just had to call createUser() on a Firebase reference, pass in the email, password and a ValueResultHandler.

Two callbacks were implemented with that ValueResultHandler:

onSuccess(Map<String, Object> result) {}

onError(FirebaseError firebaseError) {}

In onError, it was easy to grab the firebaseError to handle errors.
Like:

if (firebaseError.getCode() == FirebaseError.EMAIL_TAKEN) {}

However now with the Firebase SDK 3.0, things have changed as it is indicated on the Documentation page.

But how do we do error handling then? For example on that case with an email already taken? Thanks.

Body:
You can add new methods when you call createUserWithEmailAndPassword.
You should add the method addOnFailureListener. This is a code example:

mAuth.createUserWithEmailAndPassword(email, password).
            addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                    if (!task.isSuccessful()) {
                        Toast.makeText(this, R.string.msg_error_auth,
                                Toast.LENGTH_SHORT).show();
                    }
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                   // Here you get the error type
                   Log.d(TAG + " - On Failure", e.getMessage());
            }
    });


问:
CalendarExtender in ASP.NET
I am using a CalendarExtender control in my ASP.NET web application. I want to disable this control while clicking inside a text box. I am also using HtmlEditor (AJAX control toolkit) inside the same web page and I have only one script manager. I have done the following coding in order to get a CalendarExtender in a text box.

When I compile the program I don't get any errors, but when I click inside a text box the CalendarExtender does not appear on the web page.

```<code><%@ Page Language="C#" AutoEventWireup="true"  CodeFile="before_adm.aspx.cs"  Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>
<%@ Register Assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
.
.
.
    <asp:TextBox ID="TextBox3" runat="server">
    </asp:TextBox>
    <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox3">
    </asp:CalendarExtender>
</code>```

In web.config

```<code><add tagPrefix="asp" namespace="AjaxControlToolkit" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</code>```

Where am I going wrong? How will I get a CalendarExtender on click in a textbox.

答:
I believe you have already gone through Calendar Tutorial. Even if you have gone through, I would say just compare with that reference and you code to check what is missing?

Another thing would be copy paste their code in your project and then see if it is still working. If it is not working then you are missing some kind of config in your project and it is working then you are missing something in your page level coding.

PS: I would have tried your sample but as of now I don't have Ajax toolkit configured in my machine.

Title: CalendarExtender in ASP.NET

Body:
I am using a CalendarExtender control in my ASP.NET web application. I want to disable this control while clicking inside a text box. I am also using HtmlEditor (AJAX control toolkit) inside the same web page and I have only one script manager. I have done the following coding in order to get a CalendarExtender in a text box.

When I compile the program I don't get any errors, but when I click inside a text box the CalendarExtender does not appear on the web page.

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="before_adm.aspx.cs"  Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>
<%@ Register Assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
.
.
.
    <asp:TextBox ID="TextBox3" runat="server">
    </asp:TextBox>
    <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox3">
    </asp:CalendarExtender>

In web.config

<add tagPrefix="asp" namespace="AjaxControlToolkit" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

Where am I going wrong? How will I get a CalendarExtender on click in a textbox.


问:
Split array at index in Pharo Smalltalk
I'm having trouble with this:

```<code>Split: lista

li := Array new: 30.
aux := Array new: 30.
j := 0.
1 to: (lista size / 30) ceiling do: [ :i |
    1 to: 30 do: [ :k | aux at: k put: (lista at: k + j) ].
    j := j + 30.
    li at: i put: aux ].
^ li
</code>```

This is supossed to return the same list, but splitted in 30 groups of 30. I don't know what is failing, I've tried debugging it a lot of times, but it just doesn't work. At first I tried to split it at an index, but it's too hard.

Please, help me! :(

答:
Following the comments, I think you want something like</p>

```<code>split: lista by: anInteger
| groups j |

groups := OrderedCollection new.
j := 0.
lista withIndexDo: [:element :i | | group |
    i // anInteger = 0
       ifTrue: [ group := Array new: anInteger.
                 j := 1 ].
    group at: j put: element.
    j := j + 1.
    (j > anInteger or: [ i = lista size ])
       ifTrue: [groups add: group]. ].
^ groups
</code>```

Title: Split array at index in Pharo Smalltalk

Body:
I'm having trouble with this:

Split: lista

li := Array new: 30.
aux := Array new: 30.
j := 0.
1 to: (lista size / 30) ceiling do: [ :i |
    1 to: 30 do: [ :k | aux at: k put: (lista at: k + j) ].
    j := j + 30.
    li at: i put: aux ].
^ li

This is supossed to return the same list, but splitted in 30 groups of 30. I don't know what is failing, I've tried debugging it a lot of times, but it just doesn't work. At first I tried to split it at an index, but it's too hard.

Please, help me! :(

Body:
Following the comments, I think you want something like

split: lista by: anInteger
| groups j |

groups := OrderedCollection new.
j := 0.
lista withIndexDo: [:element :i | | group |
    i // anInteger = 0
       ifTrue: [ group := Array new: anInteger.
                 j := 1 ].
    group at: j put: element.
    j := j + 1.
    (j > anInteger or: [ i = lista size ])
       ifTrue: [groups add: group]. ].
^ groups


问:
Spring Security Entry Point Integration test differs from manual testing
I have Spring Security configured to redirect back to the home page when an unauthenticated user tries to access a report. When I manually test this, the @PreAuthorize expression triggers an AccessDeniedException which is caught by Spring's ExceptionTranslationFilter which causes a 302 Found redirect to the home page as expected.

In my integration test the exception is caught somewhere in the filter chain ahead of the ExceptionTranslationFilter and a 403 Forbidden response is returned.

Excerpt of applicationContext.xml

```<code><!-- Reports configuration -->
<bean id="homeEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
    <constructor-arg value="/" />
</bean>

<sec:http pattern="/reports/**" entry-point-ref="homeEntryPoint">
    <!-- Accessing reports requires having a previous session open so redirect to home -->
    <sec:session-management invalid-session-url="/" />
</sec:http>

<!-- Enabled security annotations (i.e. @PreAuthorize) -->
<sec:global-method-security
    secured-annotations="enabled" pre-post-annotations="enabled" />
</code>```

Integration Test

```<code>@Resource
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class SecurityConfigTest {

    @Autowired
    protected WebApplicationContext wac;

    protected MockMvc mockMvc;

    @Before
    public void setup() {
        this.mockMvc = MockMvcBuilders
                .webAppContextSetup(this.wac)
                .apply(springSecurity())
                .build();
    }

    /**
     * Test that the report endpoints will redirect to the home page
     */
    @Test
    public void testReportLoginRedirect() throws Exception {
        String endpoint = "/reports/myReportyWhichRequiresAuth.pdf";

        this.mockMvc
                .perform(get(endpoint))
                .andExpect(status().isFound()) // Error: 403 Forbidden returned
                .andExpect(redirectedUrl("/"))
                .andReturn();

    }
}
</code>```

Why is the testing setup giving a different result than the manual testing?

答:
It turns out that my manual tests automatically set an accepted media type of application/pdf (I assume due to the file extension). In the automated test the default media type accepts all. Because the response value was not PDF an HttpMediaTypeNotAcceptableException was thrown causing the exception resolver in the DispatcherServlet:processHandlerException to return a null ModelAndView and rethrow the original error.

To fix the test I set the accepted media type to application/pdf and corrected the expected redirect URL (unrelated to original error).

```<code>/**
 * Test that the report endpoints will redirect to the home page
 */
@Test
public void testReportLoginRedirect() throws Exception {
    String endpoint = "/reports/myReportyWhichRequiresAuth.pdf";

    this.mockMvc
            .perform(get(endpoint).accept(MediaType.APPLICATION_PDF))
            .andExpect(status().isFound())
            .andExpect(redirectedUrl("http://localhost/"))
            .andReturn();

}
</code>```

Body:
I have Spring Security configured to redirect back to the home page when an unauthenticated user tries to access a report. When I manually test this, the @PreAuthorize expression triggers an AccessDeniedException which is caught by Spring's ExceptionTranslationFilter which causes a 302 Found redirect to the home page as expected.

In my integration test the exception is caught somewhere in the filter chain ahead of the ExceptionTranslationFilter and a 403 Forbidden response is returned.

Excerpt of applicationContext.xml

<bean id="homeEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
    <constructor-arg value="/" />
</bean>

<sec:http pattern="/reports/**" entry-point-ref="homeEntryPoint">

    <sec:session-management invalid-session-url="/" />
</sec:http>

<sec:global-method-security
    secured-annotations="enabled" pre-post-annotations="enabled" />

Integration Test

@Resource
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class SecurityConfigTest {

    @Autowired
    protected WebApplicationContext wac;

    protected MockMvc mockMvc;

    @Before
    public void setup() {
        this.mockMvc = MockMvcBuilders
                .webAppContextSetup(this.wac)
                .apply(springSecurity())
                .build();
    }

    /**
     * Test that the report endpoints will redirect to the home page
     */
    @Test
    public void testReportLoginRedirect() throws Exception {
        String endpoint = "/reports/myReportyWhichRequiresAuth.pdf";

        this.mockMvc
                .perform(get(endpoint))
                .andExpect(status().isFound()) // Error: 403 Forbidden returned
                .andExpect(redirectedUrl("/"))
                .andReturn();

    }
}

Why is the testing setup giving a different result than the manual testing?

Body:
It turns out that my manual tests automatically set an accepted media type of application/pdf (I assume due to the file extension). In the automated test the default media type accepts all. Because the response value was not PDF an HttpMediaTypeNotAcceptableException was thrown causing the exception resolver in the DispatcherServlet:processHandlerException to return a null ModelAndView and rethrow the original error.

To fix the test I set the accepted media type to application/pdf and corrected the expected redirect URL (unrelated to original error).

/**
 * Test that the report endpoints will redirect to the home page
 */
@Test
public void testReportLoginRedirect() throws Exception {
    String endpoint = "/reports/myReportyWhichRequiresAuth.pdf";

    this.mockMvc
            .perform(get(endpoint).accept(MediaType.APPLICATION_PDF))
            .andExpect(status().isFound())
            .andExpect(redirectedUrl("http://localhost/"))
            .andReturn();

}


问:
Android Studio - devices not available when I run a project
When I try to run a project, android studio cannot find either real or virtual devices, although they are available.

If I open AVD manager, I get two virtual devices in the AVD manager window. If I run either of these from AVD manager, it creates an emulator correctly. However, when I run the app ('run' then 'run app' from the toolbar), the 'Select Deployment Target' window opens, but then says 'Nothing to show' and no devices appear.

If I connect a real device, the Select Deployment target window still says 'Nothing to show'. Also, the 'allow USB debugging' window does not appear on the device, even though USB debugging is enabled.

It was all working ok two weeks ago. Having been away, I came back yesterday to find this problem. After that, last night I had a Windows 10 update and I have updated everything connected with Android studio, and I have also created a new basic 'Hello World' app, but still no change.

Can anyone help with a solution? Has anyone had the same problem? Is there some option or setting that might need changing?

答:
Follow following steps for working real device:

First install google drivers as described on following link: https://developer.android.com/studio/run/win-usb.html

On windows open device manager and find your phone or some device named PCI and do right click and update driver then select browse my computer for drivers then go to path C:\Users\username\AppData\Local\Android\sdk\extras\google\usb_driver
then press ok, wait for finishing.

Now reconnect your device, on your device you will get a pop-up to allow, after allowing that you would be able to see your device in android studio.


问:
Copy prototype functions from object in Redux reducer
```<code>case "CONNECTOR_CONNECTION_FULFILLED":
    state = {
        ...state,
        appState: 'loggedIn'
    };
    state.ourPlayer = { ...action.payload.player }

    break;
</code>```

So when my app fires this action, it creates a player object for my app to use. The player object has prototype methods (player.spawn(), player.killed(), etc) on it though and when I copy it this way those don't get copied.

答:
The { ...someObject } object spread syntax, as well as the Object.assign method copies only the object's own enumerable properties. Non enumerable props, the prototype props, and the prototype itself are not copied.

So, while, that's not a recommended practice in the redux world, you can create some kind of a copy constructor for your domain objects, for example:

```<code>class Player {
  constructor(anotherPlayer) {
    // copy the props of another player there
  }
}
</code>```

And use it in the reducer:

```<code>case "CONNECTOR_CONNECTION_FULFILLED":
   state = {
     ...state,
     appState: 'loggedIn',
   };
   state.ourPlayer = new Player(action.payload.player)

   break;
</code>```

Body:
case "CONNECTOR_CONNECTION_FULFILLED":
    state = {
        ...state,
        appState: 'loggedIn'
    };
    state.ourPlayer = { ...action.payload.player }

    break;

So when my app fires this action, it creates a player object for my app to use. The player object has prototype methods (player.spawn(), player.killed(), etc) on it though and when I copy it this way those don't get copied.

Body:
The { ...someObject } object spread syntax, as well as the Object.assign method copies only the object's own enumerable properties. Non enumerable props, the prototype props, and the prototype itself are not copied.

So, while, that's not a recommended practice in the redux world, you can create some kind of a copy constructor for your domain objects, for example:

class Player {
  constructor(anotherPlayer) {
    // copy the props of another player there
  }
}

And use it in the reducer:

case "CONNECTOR_CONNECTION_FULFILLED":
   state = {
     ...state,
     appState: 'loggedIn',
   };
   state.ourPlayer = new Player(action.payload.player)

   break;


问:
Magento ver. 2.1.7 category home page image not saving
I am using Magento ver. 2.1.7 and when uploading category image for home page it do not save or upload the image.
I am using Agorae magento theme and I also checked the exception.log
and it says some exception see below.</p>

```<code>[2017-07-03 09:49:48] main.CRITICAL: exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('pocketgr_pglvdb'@'localhost') does not exist' in D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:228
Stack trace:
#0 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php(228): PDOStatement->execute(Array)
#1 D:\wamp\www\folder\vendor\magento\framework\DB\Statement\Pdo\Mysql.php(95): Zend_Db_Statement_Pdo->_execute(Array)
#2 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array)
#3 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Abstract.php(480): Zend_Db_Statement->execute(Array)
#4 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE `pg_cata...', Array)
#5 D:\wamp\www\folder\vendor\magento\framework\DB\Adapter\Pdo\Mysql.php(465): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE `pg_cata...', Array)
#6 D:\wamp\www\folder\vendor\magento\framework\DB\Adapter\Pdo\Mysql.php(520): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('UPDATE `pg_cata...', Array)
#7 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Abstract.php(635): Magento\Framework\DB\Adapter\Pdo\Mysql->query('UPDATE `pg_cata...', Array)
#8 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Db\UpdateRow.php(83): Zend_Db_Adapter_Abstract->update('pg_catalog_cate...', Array, Array)
#9 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Operation\Update\UpdateMain.php(57): Magento\Framework\EntityManager\Db\UpdateRow->execute('Magento\\Catalog...', Array)
#10 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Operation\Update.php(105): Magento\Framework\EntityManager\Operation\Update\UpdateMain->execute(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#11 D:\wamp\www\folder\vendor\magento\framework\EntityManager\EntityManager.php(87): Magento\Framework\EntityManager\Operation\Update->execute(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#12 D:\wamp\www\folder\vendor\magento\module-catalog\Model\ResourceModel\Category.php(1027): Magento\Framework\EntityManager\EntityManager->save(Object(Magento\Catalog\Model\Category\Interceptor))
#13 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Catalog\Model\ResourceModel\Category->save(Object(Magento\Catalog\Model\Category\Interceptor))
#14 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Catalog\Model\ResourceModel\Category\Interceptor->___callParent('save', Array)
#15 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'save', Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Array, 'clean_cache')
#16 D:\wamp\www\folder\vendor\magento\framework\App\Cache\FlushCacheByTags.php(71): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Catalog\Model\Category\Interceptor))
#17 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Framework\App\Cache\FlushCacheByTags->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#18 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'save', Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Array, 'catalogsearchFu...')
#19 D:\wamp\www\folder\vendor\magento\module-catalog-search\Model\Indexer\Fulltext\Plugin\Category.php(43): Magento\Catalog\Model\ResourceModel\Category\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Category\Interceptor))
#20 D:\wamp\www\folder\vendor\magento\module-catalog-search\Model\Indexer\Fulltext\Plugin\Category.php(29): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Category->addCommitCallback(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#21 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Category->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#22 D:\wamp\www\folder\var\generation\Magento\Catalog\Model\ResourceModel\Category\Interceptor.php(52): Magento\Catalog\Model\ResourceModel\Category\Interceptor->___callPlugins('save', Array, Array)
#23 D:\wamp\www\folder\vendor\magento\framework\Model\AbstractModel.php(631): Magento\Catalog\Model\ResourceModel\Category\Interceptor->save(Object(Magento\Catalog\Model\Category\Interceptor))
#24 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(146): Magento\Framework\Model\AbstractModel->save()
#25 D:\wamp\www\folder\var\generation\Magento\Catalog\Model\Category\Interceptor.php(26): Magento\Catalog\Model\Category\Interceptor->___callPlugins('save', Array, Array)
#26 D:\wamp\www\folder\vendor\magento\module-catalog\Controller\Adminhtml\Category\Save.php(203): Magento\Catalog\Model\Category\Interceptor->save()
#27 D:\wamp\www\folder\vendor\magento\framework\App\Action\Action.php(102): Magento\Catalog\Controller\Adminhtml\Category\Save->execute()
#28 D:\wamp\www\folder\vendor\magento\module-backend\App\AbstractAction.php(226): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#29 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#30 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->___callParent('dispatch', Array)
#31 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'dispatch', Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Array, 'adminAuthentica...')
#32 D:\wamp\www\folder\vendor\magento\module-backend\App\Action\Plugin\Authentication.php(143): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#33 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#34 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'dispatch', Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Array, 'adminMassaction...')
#35 D:\wamp\www\folder\vendor\magento\module-backend\App\Action\Plugin\MassactionKey.php(33): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#36 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#37 D:\wamp\www\folder\var\generation\Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor.php(26): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->___callPlugins('dispatch', Array, Array)
#38 D:\wamp\www\folder\vendor\magento\framework\App\FrontController.php(55): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#39 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#40 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#41 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#42 D:\wamp\www\folder\vendor\magento\framework\Module\Plugin\DbStatusValidator.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#43 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#44 D:\wamp\www\folder\var\generation\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#45 D:\wamp\www\folder\vendor\magento\framework\App\Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#46 D:\wamp\www\folder\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#47 D:\wamp\www\folder\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#48 {main}

Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('pocketgr_pglvdb'@'localhost') does not exist, query was: UPDATE `pg_catalog_category_entity` SET `attribute_set_id` = ?, `parent_id` = ?, `path` = ?, `level` = ?, `children_count` = ? WHERE (entity_id = '70')' in D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:235
Stack trace:
#0 D:\wamp\www\folder\vendor\magento\framework\DB\Statement\Pdo\Mysql.php(95): Zend_Db_Statement_Pdo->_execute(Array)
#1 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array)
#2 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE `pg_cata...', Array)
#4 D:\wamp\www\folder\vendor\magento\framework\DB\Adapter\Pdo\Mysql.php(465): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE `pg_cata...', Array)
#5 D:\wamp\www\folder\vendor\magento\framework\DB\Adapter\Pdo\Mysql.php(520): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('UPDATE `pg_cata...', Array)
#6 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Abstract.php(635): Magento\Framework\DB\Adapter\Pdo\Mysql->query('UPDATE `pg_cata...', Array)
#7 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Db\UpdateRow.php(83): Zend_Db_Adapter_Abstract->update('pg_catalog_cate...', Array, Array)
#8 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Operation\Update\UpdateMain.php(57): Magento\Framework\EntityManager\Db\UpdateRow->execute('Magento\\Catalog...', Array)
#9 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Operation\Update.php(105): Magento\Framework\EntityManager\Operation\Update\UpdateMain->execute(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#10 D:\wamp\www\folder\vendor\magento\framework\EntityManager\EntityManager.php(87): Magento\Framework\EntityManager\Operation\Update->execute(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#11 D:\wamp\www\folder\vendor\magento\module-catalog\Model\ResourceModel\Category.php(1027): Magento\Framework\EntityManager\EntityManager->save(Object(Magento\Catalog\Model\Category\Interceptor))
#12 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Catalog\Model\ResourceModel\Category->save(Object(Magento\Catalog\Model\Category\Interceptor))
#13 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Catalog\Model\ResourceModel\Category\Interceptor->___callParent('save', Array)
#14 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'save', Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Array, 'clean_cache')
#15 D:\wamp\www\folder\vendor\magento\framework\App\Cache\FlushCacheByTags.php(71): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Catalog\Model\Category\Interceptor))
#16 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Framework\App\Cache\FlushCacheByTags->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#17 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'save', Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Array, 'catalogsearchFu...')
#18 D:\wamp\www\folder\vendor\magento\module-catalog-search\Model\Indexer\Fulltext\Plugin\Category.php(43): Magento\Catalog\Model\ResourceModel\Category\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Category\Interceptor))
#19 D:\wamp\www\folder\vendor\magento\module-catalog-search\Model\Indexer\Fulltext\Plugin\Category.php(29): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Category->addCommitCallback(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#20 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Category->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#21 D:\wamp\www\folder\var\generation\Magento\Catalog\Model\ResourceModel\Category\Interceptor.php(52): Magento\Catalog\Model\ResourceModel\Category\Interceptor->___callPlugins('save', Array, Array)
#22 D:\wamp\www\folder\vendor\magento\framework\Model\AbstractModel.php(631): Magento\Catalog\Model\ResourceModel\Category\Interceptor->save(Object(Magento\Catalog\Model\Category\Interceptor))
#23 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(146): Magento\Framework\Model\AbstractModel->save()
#24 D:\wamp\www\folder\var\generation\Magento\Catalog\Model\Category\Interceptor.php(26): Magento\Catalog\Model\Category\Interceptor->___callPlugins('save', Array, Array)
#25 D:\wamp\www\folder\vendor\magento\module-catalog\Controller\Adminhtml\Category\Save.php(203): Magento\Catalog\Model\Category\Interceptor->save()
#26 D:\wamp\www\folder\vendor\magento\framework\App\Action\Action.php(102): Magento\Catalog\Controller\Adminhtml\Category\Save->execute()
#27 D:\wamp\www\folder\vendor\magento\module-backend\App\AbstractAction.php(226): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#28 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#29 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->___callParent('dispatch', Array)
#30 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'dispatch', Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Array, 'adminAuthentica...')
#31 D:\wamp\www\folder\vendor\magento\module-backend\App\Action\Plugin\Authentication.php(143): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#32 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#33 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'dispatch', Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Array, 'adminMassaction...')
#34 D:\wamp\www\folder\vendor\magento\module-backend\App\Action\Plugin\MassactionKey.php(33): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#35 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#36 D:\wamp\www\folder\var\generation\Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor.php(26): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->___callPlugins('dispatch', Array, Array)
#37 D:\wamp\www\folder\vendor\magento\framework\App\FrontController.php(55): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#38 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#39 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#40 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#41 D:\wamp\www\folder\vendor\magento\framework\Module\Plugin\DbStatusValidator.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#42 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#43 D:\wamp\www\folder\var\generation\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#44 D:\wamp\www\folder\vendor\magento\framework\App\Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#45 D:\wamp\www\folder\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#46 D:\wamp\www\folder\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#47 {main} [] []
</code>```

答:
Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('pocketgr_pglvdb'@'localhost') does not exist, query was: UPDATE pg_catalog_category_entity SET attribute_set_id = ?, parent_id = ?, path = ?, level = ?, children_count = ? WHERE (entity_id = '70')' in D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:235`

This error is generated because of not properly set user for database.

Make sure your database connection is properly established or not. and if yes check user's privileges who is connected to the database.

If you don't give full access to database user than magento will through this kind of exception.

Hope this will helps you.

Body:
I am using Magento ver. 2.1.7 and when uploading category image for home page it do not save or upload the image.
I am using Agorae magento theme and I also checked the exception.log
and it says some exception see below.

[2017-07-03 09:49:48] main.CRITICAL: exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('pocketgr_pglvdb'@'localhost') does not exist' in D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:228
Stack trace:
#0 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php(228): PDOStatement->execute(Array)
#1 D:\wamp\www\folder\vendor\magento\framework\DB\Statement\Pdo\Mysql.php(95): Zend_Db_Statement_Pdo->_execute(Array)
#2 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array)
#3 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Abstract.php(480): Zend_Db_Statement->execute(Array)
#4 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE `pg_cata...', Array)
#5 D:\wamp\www\folder\vendor\magento\framework\DB\Adapter\Pdo\Mysql.php(465): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE `pg_cata...', Array)
#6 D:\wamp\www\folder\vendor\magento\framework\DB\Adapter\Pdo\Mysql.php(520): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('UPDATE `pg_cata...', Array)
#7 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Abstract.php(635): Magento\Framework\DB\Adapter\Pdo\Mysql->query('UPDATE `pg_cata...', Array)
#8 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Db\UpdateRow.php(83): Zend_Db_Adapter_Abstract->update('pg_catalog_cate...', Array, Array)
#9 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Operation\Update\UpdateMain.php(57): Magento\Framework\EntityManager\Db\UpdateRow->execute('Magento\\Catalog...', Array)
#10 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Operation\Update.php(105): Magento\Framework\EntityManager\Operation\Update\UpdateMain->execute(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#11 D:\wamp\www\folder\vendor\magento\framework\EntityManager\EntityManager.php(87): Magento\Framework\EntityManager\Operation\Update->execute(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#12 D:\wamp\www\folder\vendor\magento\module-catalog\Model\ResourceModel\Category.php(1027): Magento\Framework\EntityManager\EntityManager->save(Object(Magento\Catalog\Model\Category\Interceptor))
#13 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Catalog\Model\ResourceModel\Category->save(Object(Magento\Catalog\Model\Category\Interceptor))
#14 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Catalog\Model\ResourceModel\Category\Interceptor->___callParent('save', Array)
#15 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'save', Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Array, 'clean_cache')
#16 D:\wamp\www\folder\vendor\magento\framework\App\Cache\FlushCacheByTags.php(71): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Catalog\Model\Category\Interceptor))
#17 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Framework\App\Cache\FlushCacheByTags->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#18 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'save', Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Array, 'catalogsearchFu...')
#19 D:\wamp\www\folder\vendor\magento\module-catalog-search\Model\Indexer\Fulltext\Plugin\Category.php(43): Magento\Catalog\Model\ResourceModel\Category\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Category\Interceptor))
#20 D:\wamp\www\folder\vendor\magento\module-catalog-search\Model\Indexer\Fulltext\Plugin\Category.php(29): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Category->addCommitCallback(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#21 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Category->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#22 D:\wamp\www\folder\var\generation\Magento\Catalog\Model\ResourceModel\Category\Interceptor.php(52): Magento\Catalog\Model\ResourceModel\Category\Interceptor->___callPlugins('save', Array, Array)
#23 D:\wamp\www\folder\vendor\magento\framework\Model\AbstractModel.php(631): Magento\Catalog\Model\ResourceModel\Category\Interceptor->save(Object(Magento\Catalog\Model\Category\Interceptor))
#24 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(146): Magento\Framework\Model\AbstractModel->save()
#25 D:\wamp\www\folder\var\generation\Magento\Catalog\Model\Category\Interceptor.php(26): Magento\Catalog\Model\Category\Interceptor->___callPlugins('save', Array, Array)
#26 D:\wamp\www\folder\vendor\magento\module-catalog\Controller\Adminhtml\Category\Save.php(203): Magento\Catalog\Model\Category\Interceptor->save()
#27 D:\wamp\www\folder\vendor\magento\framework\App\Action\Action.php(102): Magento\Catalog\Controller\Adminhtml\Category\Save->execute()
#28 D:\wamp\www\folder\vendor\magento\module-backend\App\AbstractAction.php(226): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#29 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#30 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->___callParent('dispatch', Array)
#31 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'dispatch', Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Array, 'adminAuthentica...')
#32 D:\wamp\www\folder\vendor\magento\module-backend\App\Action\Plugin\Authentication.php(143): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#33 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#34 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'dispatch', Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Array, 'adminMassaction...')
#35 D:\wamp\www\folder\vendor\magento\module-backend\App\Action\Plugin\MassactionKey.php(33): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#36 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#37 D:\wamp\www\folder\var\generation\Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor.php(26): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->___callPlugins('dispatch', Array, Array)
#38 D:\wamp\www\folder\vendor\magento\framework\App\FrontController.php(55): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#39 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#40 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#41 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#42 D:\wamp\www\folder\vendor\magento\framework\Module\Plugin\DbStatusValidator.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#43 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#44 D:\wamp\www\folder\var\generation\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#45 D:\wamp\www\folder\vendor\magento\framework\App\Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#46 D:\wamp\www\folder\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#47 D:\wamp\www\folder\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#48 {main}

Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY000]: General error: 1449 The user specified as a definer ('pocketgr_pglvdb'@'localhost') does not exist, query was: UPDATE `pg_catalog_category_entity` SET `attribute_set_id` = ?, `parent_id` = ?, `path` = ?, `level` = ?, `children_count` = ? WHERE (entity_id = '70')' in D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:235
Stack trace:
#0 D:\wamp\www\folder\vendor\magento\framework\DB\Statement\Pdo\Mysql.php(95): Zend_Db_Statement_Pdo->_execute(Array)
#1 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array)
#2 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE `pg_cata...', Array)
#4 D:\wamp\www\folder\vendor\magento\framework\DB\Adapter\Pdo\Mysql.php(465): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE `pg_cata...', Array)
#5 D:\wamp\www\folder\vendor\magento\framework\DB\Adapter\Pdo\Mysql.php(520): Magento\Framework\DB\Adapter\Pdo\Mysql->_query('UPDATE `pg_cata...', Array)
#6 D:\wamp\www\folder\vendor\magento\zendframework1\library\Zend\Db\Adapter\Abstract.php(635): Magento\Framework\DB\Adapter\Pdo\Mysql->query('UPDATE `pg_cata...', Array)
#7 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Db\UpdateRow.php(83): Zend_Db_Adapter_Abstract->update('pg_catalog_cate...', Array, Array)
#8 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Operation\Update\UpdateMain.php(57): Magento\Framework\EntityManager\Db\UpdateRow->execute('Magento\\Catalog...', Array)
#9 D:\wamp\www\folder\vendor\magento\framework\EntityManager\Operation\Update.php(105): Magento\Framework\EntityManager\Operation\Update\UpdateMain->execute(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#10 D:\wamp\www\folder\vendor\magento\framework\EntityManager\EntityManager.php(87): Magento\Framework\EntityManager\Operation\Update->execute(Object(Magento\Catalog\Model\Category\Interceptor), Array)
#11 D:\wamp\www\folder\vendor\magento\module-catalog\Model\ResourceModel\Category.php(1027): Magento\Framework\EntityManager\EntityManager->save(Object(Magento\Catalog\Model\Category\Interceptor))
#12 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Catalog\Model\ResourceModel\Category->save(Object(Magento\Catalog\Model\Category\Interceptor))
#13 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Catalog\Model\ResourceModel\Category\Interceptor->___callParent('save', Array)
#14 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'save', Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Array, 'clean_cache')
#15 D:\wamp\www\folder\vendor\magento\framework\App\Cache\FlushCacheByTags.php(71): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Catalog\Model\Category\Interceptor))
#16 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Framework\App\Cache\FlushCacheByTags->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#17 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'save', Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Array, 'catalogsearchFu...')
#18 D:\wamp\www\folder\vendor\magento\module-catalog-search\Model\Indexer\Fulltext\Plugin\Category.php(43): Magento\Catalog\Model\ResourceModel\Category\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Catalog\Model\Category\Interceptor))
#19 D:\wamp\www\folder\vendor\magento\module-catalog-search\Model\Indexer\Fulltext\Plugin\Category.php(29): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Category->addCommitCallback(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#20 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\CatalogSearch\Model\Indexer\Fulltext\Plugin\Category->aroundSave(Object(Magento\Catalog\Model\ResourceModel\Category\Interceptor), Object(Closure), Object(Magento\Catalog\Model\Category\Interceptor))
#21 D:\wamp\www\folder\var\generation\Magento\Catalog\Model\ResourceModel\Category\Interceptor.php(52): Magento\Catalog\Model\ResourceModel\Category\Interceptor->___callPlugins('save', Array, Array)
#22 D:\wamp\www\folder\vendor\magento\framework\Model\AbstractModel.php(631): Magento\Catalog\Model\ResourceModel\Category\Interceptor->save(Object(Magento\Catalog\Model\Category\Interceptor))
#23 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(146): Magento\Framework\Model\AbstractModel->save()
#24 D:\wamp\www\folder\var\generation\Magento\Catalog\Model\Category\Interceptor.php(26): Magento\Catalog\Model\Category\Interceptor->___callPlugins('save', Array, Array)
#25 D:\wamp\www\folder\vendor\magento\module-catalog\Controller\Adminhtml\Category\Save.php(203): Magento\Catalog\Model\Category\Interceptor->save()
#26 D:\wamp\www\folder\vendor\magento\framework\App\Action\Action.php(102): Magento\Catalog\Controller\Adminhtml\Category\Save->execute()
#27 D:\wamp\www\folder\vendor\magento\module-backend\App\AbstractAction.php(226): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#28 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))
#29 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->___callParent('dispatch', Array)
#30 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'dispatch', Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Array, 'adminAuthentica...')
#31 D:\wamp\www\folder\vendor\magento\module-backend\App\Action\Plugin\Authentication.php(143): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#32 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#33 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Catalog...', 'dispatch', Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Array, 'adminMassaction...')
#34 D:\wamp\www\folder\vendor\magento\module-backend\App\Action\Plugin\MassactionKey.php(33): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#35 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Backend\App\Action\Plugin\MassactionKey->aroundDispatch(Object(Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#36 D:\wamp\www\folder\var\generation\Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor.php(26): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->___callPlugins('dispatch', Array, Array)
#37 D:\wamp\www\folder\vendor\magento\framework\App\FrontController.php(55): Magento\Catalog\Controller\Adminhtml\Category\Save\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#38 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#39 D:\wamp\www\folder\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#40 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#41 D:\wamp\www\folder\vendor\magento\framework\Module\Plugin\DbStatusValidator.php(69): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#42 D:\wamp\www\folder\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#43 D:\wamp\www\folder\var\generation\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#44 D:\wamp\www\folder\vendor\magento\framework\App\Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#45 D:\wamp\www\folder\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#46 D:\wamp\www\folder\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#47 {main} [] []


问:
How can I split a URL string up into separate parts in Python?
I decided that I'll learn Python tonight :)
I know C pretty well (wrote an OS in it), so I'm not a noob in programming, so everything in Python seems pretty easy, but I don't know how to solve this problem:
let's say I have this address:

http://example.com/random/folder/path.html

Now how can I create two strings from this, one containing the "base" name of the server, so in this example it would be

http://example.com/

and another containing the thing without the last filename, so in this example it would be

http://example.com/random/folder/

Also I of course know the possibility to just find the third and last slash respectively, but is there a better way?

Also it would be cool to have the trailing slash in both cases, but I don't care since it can be added easily.
So is there a good, fast, effective solution for this? Or is there only "my" solution, finding the slashes?

答: I have no experience with Python, but I found the urlparse module, which should do the job.</p>

OwnerDisplayName: Language

LastEditorDisplayName: Simucal

OwnerDisplayName: Sebastian Dietz


问:
React Native multiline, value, smaller than placeholder in TextInput component
When adding text into a <TextInput> component with multiline set to false the value text matches the placeholder text font size, whereas if multiline is equal to true, the value text font size is smaller than the placeholder font size.

Is this a normal behaviour or a bug?

Edit:

```<code>/* @flow */

import React from 'react'
import Separator from './components/Separator'
import {Button, StyleSheet, TextInput, View} from 'react-native'

const styles = StyleSheet.create({
    subject: {
        height: 20,
    },
    body: {
        height: 100,
    },
})

export default class NewQuestion extends React.Component {
    static navigationOptions = ({navigation}) => ({
        title: 'AIBU',
        headerLeft: (
            <Button
                onPress={() => {
                    navigation.goBack()
                }}
                title="Back"
            />
        ),
    })

    state = {
        subject: '',
        body: '',
    }

    render() {
        return (
            <View>
                <TextInput
                    autoFocus
                    onChangeText={subject => this.setState({subject})}
                    placeholder="Enter your AIBU subject..."
                    style={styles.subject}
                    value={this.state.subject}
                />
                <Separator />
                <TextInput
                    multiline
                    onChangeText={body => this.setState({body})}
                    placeholder="Enter your AIBU description..."
                    style={styles.body}
                    value={this.state.body}
                />
            </View>
        )
    }
}
</code>```

答:
As far as I see, the default font size is actually different for multiline and non-multiline TextInput-s. One way to handle this is by introducing another component which acts as an abstraction on top of TextInput:

const styles = StyleSheet.create({
    text: {
        fontFamily: 'System',
        fontStyle: 'normal',
        fontSize: 20,
        lineHeight: 20,
        letterSpacing: 0.6
    }
})

export default class AppTextInput extends Component {
    static propTypes = {
        style: TextInput.propTypes.style
    }

    static defaultProps = {
        style: {}
    }

    render() {
        return (
            <TextInput
                {...this.props}
                style={[
                    styles.text,
                    this.props.style
                ]}
            />
        )
    }
}```

Now you can just use AppTextInput the same way TextInput is supposed to be used, and all issues related to styling inputs are covered in a single place.

Body:
When adding text into a <TextInput> component with multiline set to false the value text matches the placeholder text font size, whereas if multiline is equal to true, the value text font size is smaller than the placeholder font size.

Is this a normal behaviour or a bug?

Edit:

/* @flow */

import React from 'react'
import Separator from './components/Separator'
import {Button, StyleSheet, TextInput, View} from 'react-native'

const styles = StyleSheet.create({
    subject: {
        height: 20,
    },
    body: {
        height: 100,
    },
})

export default class NewQuestion extends React.Component {
    static navigationOptions = ({navigation}) => ({
        title: 'AIBU',
        headerLeft: (
            <Button
                onPress={() => {
                    navigation.goBack()
                }}
                title="Back"
            />
        ),
    })

    state = {
        subject: '',
        body: '',
    }

    render() {
        return (
            <View>
                <TextInput
                    autoFocus
                    onChangeText={subject => this.setState({subject})}
                    placeholder="Enter your AIBU subject..."
                    style={styles.subject}
                    value={this.state.subject}
                />
                <Separator />
                <TextInput
                    multiline
                    onChangeText={body => this.setState({body})}
                    placeholder="Enter your AIBU description..."
                    style={styles.body}
                    value={this.state.body}
                />
            </View>
        )
    }
}

Body:
As far as I see, the default font size is actually different for multiline and non-multiline TextInput-s. One way to handle this is by introducing another component which acts as an abstraction on top of TextInput:

const styles = StyleSheet.create({
    text: {
        fontFamily: 'System',
        fontStyle: 'normal',
        fontSize: 20,
        lineHeight: 20,
        letterSpacing: 0.6
    }
})

export default class AppTextInput extends Component {
    static propTypes = {
        style: TextInput.propTypes.style
    }

    static defaultProps = {
        style: {}
    }

    render() {
        return (
            <TextInput
                {...this.props}
                style={[
                    styles.text,
                    this.props.style
                ]}
            />
        )
    }
}

Now you can just use AppTextInput the same way TextInput is supposed to be used, and all issues related to styling inputs are covered in a single place.


问:
Regex for counting occurrences of a string within a single cell in Google Sheets
I have a Google Sheet filled with data and cells, and would like to get the number of times a string appears in a particular cell, as well as how many times a string appears in total for a single column. For example, I am trying to count the number of "of" strings in a column as follows:

```<code>=COUNTA(FILTER('Data Sheet'!G3:G313, REGEXMATCH('Data Sheet'!G3:G313, "of")))
</code>```

However, this just returns the number of cells with an "of". How do I get the total count of "of" strings.

答:
For a single cell, you can use

```<code>=(len(G3)-len(substitute(G3, "of",)))/2
</code>```

To count the number of occurrences in a column try

```<code>=sum(ArrayFormula(if(len(G3:G), (len(G3:G7)-len(substitute(G3:G, "of",)))/2,)))
</code>```

Note: 2 refers to the number of characters of the string to count( "of")

Change range to suit and see if that works?

Body:
I have a Google Sheet filled with data and cells, and would like to get the number of times a string appears in a particular cell, as well as how many times a string appears in total for a single column. For example, I am trying to count the number of "of" strings in a column as follows:

=COUNTA(FILTER('Data Sheet'!G3:G313, REGEXMATCH('Data Sheet'!G3:G313, "of")))

However, this just returns the number of cells with an "of". How do I get the total count of "of" strings.

Body:
For a single cell, you can use

=(len(G3)-len(substitute(G3, "of",)))/2

To count the number of occurrences in a column try

=sum(ArrayFormula(if(len(G3:G), (len(G3:G7)-len(substitute(G3:G, "of",)))/2,)))

Note: 2 refers to the number of characters of the string to count( "of")

Change range to suit and see if that works?


问:
Passing a function as an argument
I am teaching myself javascript and one of the exercises I have tried makes no sense to me.

In the code below 'position' is a parameter that must be defined. However, when I pass the function, displayLocation as an argument to navigator.geolocation.getCurrentPosition, the code executes flawlessly, despite no argument being passed. When I try coords.longitude in the console without the position argument, it does not work.

How does the code work without a defined argument?

```<code>function displayLocation(position)
{
  var latitude = latitude.coords.latitude;
  var longitude = position.coords.longitude;
  var div = document.getElementById("location");
  div.innerHTML = latitude + " " + longitude;
}

navigator.geolocation.getCurrentPosition(displayLocation);
</code>```

答:
Let's take a look at Geolocation.getCurrentPosition. The required parameter success is a callback function.

Inner workings of the Geolocation.getCurrentPosition(displayLocation) will look roughly like the following:

```<code>function getCurrentPosition(callback, ...){

  var positionGCP;
  ...
  ...

  positionGCP = *someposition*;
  // done getting current position

  callback(positionGCP)
  //passed in function gets called back!
}
</code>```

and the last line (callback(positionGCP)) really runs displayLocation(positionGCP) since callback == displayLocation.

Does that make sense?

The following link may help:
Passing parameters to a callback function

Title: Passing a function as an argument

Body:
I am teaching myself javascript and one of the exercises I have tried makes no sense to me.

In the code below 'position' is a parameter that must be defined. However, when I pass the function, displayLocation as an argument to navigator.geolocation.getCurrentPosition, the code executes flawlessly, despite no argument being passed. When I try coords.longitude in the console without the position argument, it does not work.

How does the code work without a defined argument?

function displayLocation(position)
{
  var latitude = latitude.coords.latitude;
  var longitude = position.coords.longitude;
  var div = document.getElementById("location");
  div.innerHTML = latitude + " " + longitude;
}

navigator.geolocation.getCurrentPosition(displayLocation);

Body:
Let's take a look at Geolocation.getCurrentPosition. The required parameter success is a callback function.

Inner workings of the Geolocation.getCurrentPosition(displayLocation) will look roughly like the following:

function getCurrentPosition(callback, ...){

  var positionGCP;
  ...
  ...

  positionGCP = *someposition*;
  // done getting current position

  callback(positionGCP)
  //passed in function gets called back!
}

and the last line (callback(positionGCP)) really runs displayLocation(positionGCP) since callback == displayLocation.

Does that make sense?

The following link may help:
Passing parameters to a callback function


问:
setImageBitmap() is not working
I have and ImageView and it is supposed to be filled with an image from Gallery with this code:

```<code>Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
            getIntent.setType("image/*");
            Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            pickIntent.setType("image/*");

            Intent chooserIntent = Intent.createChooser(getIntent, "Pick an image.");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});

            startActivityForResult(chooserIntent, PICK_IMAGE_REQUEST);
</code>```

Now, everything's fine in this part of the code, the problem is in onActivityResult(), exactly in setImageBitmap() because imageView is not adopting the image from Gallery. This is the code from onActivityResult():

```<code>@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode == PICK_IMAGE_REQUEST || resultCode == PromoUpload.RESULT_OK){

        Uri selectedImage = data.getData();
        String[] filepathColumm = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filepathColumm, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filepathColumm[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
        imagePromo.setImageBitmap(bitmap);
        pictureFlag = 1;

    }
</code>```

I Toast the picturePath attribute and it's displayed ok, the problem is exactly here:

```<code>Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
    imagePromo.setImageBitmap(bitmap);
</code>```

But I don't know what I'm doing wrong. This is the XML of the ImageView:

```<code><ImageView
        android:id="@+id/imageView_promo"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerHorizontal="true"
        android:padding="1dp" />
</code>```

I also tried selecting images from multiple sizes, but it doesn't seem to work...

答:
But I don't know what I'm doing wrong

You are assuming that every Uri is from the MediaStore and that every entry in the MediaStore has a useful path. Neither is true.

What you should be doing is passing selectedImage to an image-loading library (Glide, Picasso, etc.), as those libraries not only know how to use the Uri properly, but they will do the image-loading on a background thread, rather than freezing the UI as you are doing here. You can also teach the image-loading library to scale the image to fit your ImageView, to save on heap space.

A more direct replacement for your code would be:

```<code>    Uri selectedImage = data.getData();
    Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage));
    imagePromo.setImageBitmap(bitmap);
    pictureFlag = 1;
</code>```

But, as noted, this will freeze your UI while the disk I/O and image decoding is going on.

Title: setImageBitmap() is not working

Body:
I have and ImageView and it is supposed to be filled with an image from Gallery with this code:

Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
            getIntent.setType("image/*");
            Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            pickIntent.setType("image/*");

            Intent chooserIntent = Intent.createChooser(getIntent, "Pick an image.");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});

            startActivityForResult(chooserIntent, PICK_IMAGE_REQUEST);

Now, everything's fine in this part of the code, the problem is in onActivityResult(), exactly in setImageBitmap() because imageView is not adopting the image from Gallery. This is the code from onActivityResult():

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode == PICK_IMAGE_REQUEST || resultCode == PromoUpload.RESULT_OK){

        Uri selectedImage = data.getData();
        String[] filepathColumm = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filepathColumm, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filepathColumm[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
        imagePromo.setImageBitmap(bitmap);
        pictureFlag = 1;

    }

I Toast the picturePath attribute and it's displayed ok, the problem is exactly here:

Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
    imagePromo.setImageBitmap(bitmap);

But I don't know what I'm doing wrong. This is the XML of the ImageView:

<ImageView
        android:id="@+id/imageView_promo"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerHorizontal="true"
        android:padding="1dp" />

I also tried selecting images from multiple sizes, but it doesn't seem to work...

Body:
But I don't know what I'm doing wrong

You are assuming that every Uri is from the MediaStore and that every entry in the MediaStore has a useful path. Neither is true.

What you should be doing is passing selectedImage to an image-loading library (Glide, Picasso, etc.), as those libraries not only know how to use the Uri properly, but they will do the image-loading on a background thread, rather than freezing the UI as you are doing here. You can also teach the image-loading library to scale the image to fit your ImageView, to save on heap space.

A more direct replacement for your code would be:

    Uri selectedImage = data.getData();
    Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage));
    imagePromo.setImageBitmap(bitmap);
    pictureFlag = 1;

But, as noted, this will freeze your UI while the disk I/O and image decoding is going on.