问:
connect "caps" of box plot
hello i have a python function to connect the "caps" of 2 boxplots, but i can't conect only the superior caps, and that's what I need(only connect it the superior caps with the pink line), i very appreciate a lot you help,

my code is the next

```<code>def set_boxes_lim_max_line(bp, w, c):
    limit_sup_x = []
    limit_sup_y = []

    for p in bp['caps']:
        data = p.get_data()
        #x=bp['caps'][1].get_data()[0]
        x=np.max([data[0].mean(),data[0].mean()])
        #x=bp['boxes'][0].get_data()[0]
        y = data[1].max()
        limit_sup_x.append(x)
        limit_sup_y.append(y)

    plt.plot(limit_sup_x,limit_sup_y, color = c, linewidth = w)
    #plt.plot(limit_sup_x, color = c, linewidth = w)

</code>```

the function that calls it:

```<code> bp1 = plt.boxplot([sample1[i] for i in posiciones2], positions = (range(1, 3)), widths = 0.6)
    set_box_color(bp1,'red')

    # Agregar lineas caja roja
    set_boxes_lim_max_line(bp1,1.2,'hotpink')#LINEA LIMITE SUPERIOR
    set_boxes_q_min_line(bp1, 1.2, 'tomato') #LINEA "Q3" SUPERIOR CAJA
    set_boxes_median_line(bp1, 1.2, 'seagreen')#LINEA MEDIANA
    set_boxes_q_max_line(bp1, 1.2, 'darkred')#LINEA "Q1" INFERIOR CAJA
    #set_boxes_q_min_line(bp1, 1.2, 'tomato') #LINEA LIMITE INFERIOR
</code>```

答:
This will do it:

```<code>def set_boxes_lim_max_line(bp, w, c):
    limit_sup_x = []
    limit_sup_y = []

    for p in bp['caps'][1::2]:
        data = p.get_data()
        #x=bp['caps'][1].get_data()[0]
        x=np.max([data[0].mean(),data[0].mean()])
        #x=bp['boxes'][0].get_data()[0]
        y = data[1].max()
        limit_sup_x.append(x)
        limit_sup_y.append(y)

    plt.plot(limit_sup_x,limit_sup_y, color = c, linewidth = w)
</code>```

Example:

Title: connect "caps" of box plot

Body:
hello i have a python function to connect the "caps" of 2 boxplots, but i can't conect only the superior caps, and that's what I need(only connect it the superior caps with the pink line), i very appreciate a lot you help,

my code is the next

def set_boxes_lim_max_line(bp, w, c):
    limit_sup_x = []
    limit_sup_y = []

    for p in bp['caps']:
        data = p.get_data()
        #x=bp['caps'][1].get_data()[0]
        x=np.max([data[0].mean(),data[0].mean()])
        #x=bp['boxes'][0].get_data()[0]
        y = data[1].max()
        limit_sup_x.append(x)
        limit_sup_y.append(y)

    plt.plot(limit_sup_x,limit_sup_y, color = c, linewidth = w)
    #plt.plot(limit_sup_x, color = c, linewidth = w)

the function that calls it:

 bp1 = plt.boxplot([sample1[i] for i in posiciones2], positions = (range(1, 3)), widths = 0.6)
    set_box_color(bp1,'red')

    # Agregar lineas caja roja
    set_boxes_lim_max_line(bp1,1.2,'hotpink')#LINEA LIMITE SUPERIOR
    set_boxes_q_min_line(bp1, 1.2, 'tomato') #LINEA "Q3" SUPERIOR CAJA
    set_boxes_median_line(bp1, 1.2, 'seagreen')#LINEA MEDIANA
    set_boxes_q_max_line(bp1, 1.2, 'darkred')#LINEA "Q1" INFERIOR CAJA
    #set_boxes_q_min_line(bp1, 1.2, 'tomato') #LINEA LIMITE INFERIOR

Body:
This will do it:

def set_boxes_lim_max_line(bp, w, c):
    limit_sup_x = []
    limit_sup_y = []

    for p in bp['caps'][1::2]:
        data = p.get_data()
        #x=bp['caps'][1].get_data()[0]
        x=np.max([data[0].mean(),data[0].mean()])
        #x=bp['boxes'][0].get_data()[0]
        y = data[1].max()
        limit_sup_x.append(x)
        limit_sup_y.append(y)

    plt.plot(limit_sup_x,limit_sup_y, color = c, linewidth = w)

Example:


来源: stackexchange

问:
Can you safely synchronize on a Java method parameter?
Take this code:

```<code>public class MyClass {
    private final Object _lock = new Object();
    private final MyMutableClass _mutableObject = new MyMutableClass()

    public void myMethod() {
        synchronized(_lock) { // we are synchronizing on instance variable _lock
            // do something with mutableVar
            //(i.e. call a "set" method on _mutableObject)
        }
    }
}
</code>```

now, imagine delegating the code inside myMethod() to some helper class where you pass the lock

```<code>public class HelperClass {
    public helperMethod(Object lockVar, MyMutableClass mutableVar) {
        synchronized(lockVar) { // we are now synchronizing on a method param,
                                // each thread has own copy
            // do something with mutableVar
            // (i.e. call a "set" method on mutableVar)
        }
    }
}
</code>```

can "myMethod" be re-written to use the HelperClass by passing its lock var, so that everything is still thread safe?  i.e.,

```<code>public void myMethod() {
    _helperObject.helperMethod(_lock, _mutableObject);
}
</code>```

I am not sure about this, because Java will pass the lockVar by value, and every thread will get a separate copy of lockVar (even though each copy points to the same object on the heap).  I guess the question comes down to how 'synchronized' keyword works -- does it lock on the variable, or the value on the heap that the variable references?

答:
Synchronization is done upon objects, not variables.

Variables/members [sometimes] contain objects and it is the resulting object contained in [variable] x that is actually synchronized upon in synchronized(x).

There are a few other issues with thread-visibility of variables (e.g. might read a "stale" object from a variable), but that does not apply here: there is no re-assignment of _lock and the visibility of the initial ("final") assignment is guaranteed. Because of this it is guaranteed that, in this case, the method parameter will always contain the correct (same) object used for the synchronization.

If the lock object used (where presumably _lock is not final) changes, however, then that would require re-evaluation of the appropriate values/thread-visibility but otherwise does not differ from any cross-thread access.

Happy coding.

ContentLicense: CC BY-SA 3.0

Body:
Take this code:

public class MyClass {
    private final Object _lock = new Object();
    private final MyMutableClass _mutableObject = new MyMutableClass()

    public void myMethod() {
        synchronized(_lock) { // we are synchronizing on instance variable _lock
            // do something with mutableVar
            //(i.e. call a "set" method on _mutableObject)
        }
    }
}

now, imagine delegating the code inside myMethod() to some helper class where you pass the lock

public class HelperClass {
    public helperMethod(Object lockVar, MyMutableClass mutableVar) {
        synchronized(lockVar) { // we are now synchronizing on a method param,
                                // each thread has own copy
            // do something with mutableVar
            // (i.e. call a "set" method on mutableVar)
        }
    }
}

can "myMethod" be re-written to use the HelperClass by passing its lock var, so that everything is still thread safe?  i.e.,

public void myMethod() {
    _helperObject.helperMethod(_lock, _mutableObject);
}

I am not sure about this, because Java will pass the lockVar by value, and every thread will get a separate copy of lockVar (even though each copy points to the same object on the heap).  I guess the question comes down to how 'synchronized' keyword works -- does it lock on the variable, or the value on the heap that the variable references?


问:
Python one class per module and packages
I'm trying to structure my app in Python. Coming back from C#/Java background, I like the approach of one class per file. I'd like my project tree to look like this:

```<code>[Service]
    [Database]
        DbClass1.py
        DbClass2.py
    [Model]
        DbModel1.py
        DbModel2.py
    TheService.py
[ServiceTests]
    [Database]
        DbClass1Tests.py
        DbClass2Tests.py
    [Model]
        DbModel1Tests.py
        DbModel2Tests.py
    TheServiceTests.py
</code>```

Is the one class per file approach OK in Python?

Is it possible to create packages/modules in such a way so that packages work like Java's packages or .NET's namespaces, i.e. in DbModel1Tests.py:

```<code>import Service.Model

def test():
   m = DbModel1()
</code>```

答: A python system is a set of modules, each module has a target, so you need use the most suitable approach to reach the target, it includes a class per module or a mix of functions and classes per module.</p>

Body:
I'm trying to structure my app in Python. Coming back from C#/Java background, I like the approach of one class per file. I'd like my project tree to look like this:

[Service]
    [Database]
        DbClass1.py
        DbClass2.py
    [Model]
        DbModel1.py
        DbModel2.py
    TheService.py
[ServiceTests]
    [Database]
        DbClass1Tests.py
        DbClass2Tests.py
    [Model]
        DbModel1Tests.py
        DbModel2Tests.py
    TheServiceTests.py

Is the one class per file approach OK in Python?

Is it possible to create packages/modules in such a way so that packages work like Java's packages or .NET's namespaces, i.e. in DbModel1Tests.py:

import Service.Model

def test():
   m = DbModel1()

ContentLicense: CC BY-SA 4.0


问:
why does "npm run build" produce error "react-scripts Permission denied"?
I'm on Ubuntu 18.04, logged in as root.  The group:owner of /root/.npm is root:root, recursively, and all permissions are 777, recursively.  If I cd to the React folder:

```<code>cd /var/lib/jenkins/workspace/MedAverter/medaverter-front
</code>```

And set all permissions of that folder to 777, recursively and then run

```<code>npm run build
</code>```

I get error:

[[1;34mINFO[m] Running 'npm run build' in
  /var/lib/jenkins/workspace/MedAverter/medaverter-front
  [[1;34mINFO[m]  [[1;34mINFO[m] > medaverter-front@0.1.0 build
  /var/lib/jenkins/workspace/MedAverter/medaverter-front
  [[1;34mINFO[m] > react-scripts build [[1;34mINFO[m]
  [[1;31mERROR[m] sh: 1: react-scripts: Permission denied
  [[1;31mERROR[m] npm ERR! code ELIFECYCLE [[1;31mERROR[m] npm ERR!
  errno 126 [[1;31mERROR[m] npm ERR! medaverter-front@0.1.0 build:
  react-scripts build [[1;31mERROR[m] npm ERR! Exit status 126
  [[1;31mERROR[m] npm ERR!  [[1;31mERROR[m] npm ERR! Failed at the
  medaverter-front@0.1.0 build script.

I've been googling for a solution for hours with no luck.  It builds fine under Windows 10.
Suggestions?

答:
Since I am unable to comment.

Personally, I have followed this answer and chosen Solution 2.

After reading more about this you shouldn't be giving npm sudo/root permissions. You are putting way too much faith in the scripts. Rather update your npm by following that guide and you will no longer have that issue.

Did that for my raspberry pi.

Body:
I'm on Ubuntu 18.04, logged in as root.  The group:owner of /root/.npm is root:root, recursively, and all permissions are 777, recursively.  If I cd to the React folder:

cd /var/lib/jenkins/workspace/MedAverter/medaverter-front

And set all permissions of that folder to 777, recursively and then run

npm run build

I get error:

[[1;34mINFO[m] Running 'npm run build' in
  /var/lib/jenkins/workspace/MedAverter/medaverter-front
  [[1;34mINFO[m]  [[1;34mINFO[m] > medaverter-front@0.1.0 build
  /var/lib/jenkins/workspace/MedAverter/medaverter-front
  [[1;34mINFO[m] > react-scripts build [[1;34mINFO[m]
  [[1;31mERROR[m] sh: 1: react-scripts: Permission denied
  [[1;31mERROR[m] npm ERR! code ELIFECYCLE [[1;31mERROR[m] npm ERR!
  errno 126 [[1;31mERROR[m] npm ERR! medaverter-front@0.1.0 build:
  react-scripts build [[1;31mERROR[m] npm ERR! Exit status 126
  [[1;31mERROR[m] npm ERR!  [[1;31mERROR[m] npm ERR! Failed at the
  medaverter-front@0.1.0 build script.

I've been googling for a solution for hours with no luck.  It builds fine under Windows 10.
Suggestions?


问:
Database design for multiple game variations
Hopefully the purpose of these tables will be apparent, but just in case here's a simple explanation: I basically wish to store the results of matches (8 ball pool etc.) but also log the results on a frame by frame basis. Where I am getting a problem is that I intend to allow for different game types as my application grows, and as such, the scoring system used within each frame would vary. I think the solution below could work, but it doesn't quite seem right to me, all advice is appreciated.

Is there a more sensible approach than using the following tables:

# Players

id

name

nickname

# NormalMatches

id

playerA

playerB

# NormalFrames

id

match_id

playerAWon (BOOL)

# ScoringPoolMatches

id

playerA

playerB

# ScoringPoolFrames

id

match_id

playerA_cue_ball_potted

playerB_cue_ball_potted

playerA_balls_potted

playerB_balls_potted

playerA_balls_remaining

playerB_balls_remaining

(edit: altered ScoringPoolFrame table to give better idea of what the problem is.)

Many thanks.

答:
Guiding principle: Less is more. In this case, less tables = good.

A match is a match and a frame is a frame, so...

Merge "NormalMatches" and "ScoringPoolMatches" tables together and introduce a column is_scoring boolean to differentiate

Merge the "NormalFrames" and "ScoringPoolFrames" tables into simply "Frames" (id, playerA_score, playerB_score), but simply allocate a score of "1" for a win and "0" for a loss for normal games. Then your calculation of win/lose is the same for all frames.

Create view(s) to capture the logic of calculations, eg

```<code>CREATE VIEW FRAME_RESULT AS
SELECT
    id,
    playerA_score > playerB_score as playerAWon,
    playerB_score > playerA_score as playerBWon,
    playerA_score = playerB_score as is_draw
FROM Frames
</code>```

Body:
Guiding principle: Less is more. In this case, less tables = good.

A match is a match and a frame is a frame, so...

Merge "NormalMatches" and "ScoringPoolMatches" tables together and introduce a column is_scoring boolean to differentiate

Merge the "NormalFrames" and "ScoringPoolFrames" tables into simply "Frames" (id, playerA_score, playerB_score), but simply allocate a score of "1" for a win and "0" for a loss for normal games. Then your calculation of win/lose is the same for all frames.

Create view(s) to capture the logic of calculations, eg

CREATE VIEW FRAME_RESULT AS
SELECT
    id,
    playerA_score > playerB_score as playerAWon,
    playerB_score > playerA_score as playerBWon,
    playerA_score = playerB_score as is_draw
FROM Frames


问:
select all the rows from my table except the first 20 rows
I want to select all the rows from my table except the first 20 rows. How it possible? The total number of rows are not static.

```<code>SELECT statistics_id,title, user_name FROM (
    SELECT statistics_id,title, user_name FROM statistics ORDER BY statistics_id DESC
    LIMIT(select count(*)from statistics )-20
) sub
ORDER BY access_statistics_id ASC
</code>```

I know 'LIMIT(select count(*)from statistics )-20'  is not a correct method. Please help.

答:
If your table grows fast, selecting all rows (with exception of first 20) is not a good idea. In such case, you should batch your query, and handle a subset of entries at a time, some thing like:

SELECT * FROM tbl LIMIT 20,120;

Body:
I want to select all the rows from my table except the first 20 rows. How it possible? The total number of rows are not static.

SELECT statistics_id,title, user_name FROM (
    SELECT statistics_id,title, user_name FROM statistics ORDER BY statistics_id DESC
    LIMIT(select count(*)from statistics )-20
) sub
ORDER BY access_statistics_id ASC

I know 'LIMIT(select count(*)from statistics )-20'  is not a correct method. Please help.


问:
Auto Scroll Down a shell usin jsch
I am facing a problem in Java jsch. I have opened a Shell channel and I have a list of commands that I want to execute and read from the shell.

But in that commands list, there's one command that needs to be scrolled down in the shell to be shown until its end.

I am strugling to implement this auto-scroller for that command.

In my code What I did:

```<code>    ChannelShell channelShell = (ChannelShell) session.openChannel("shell");
    OutputStream inputstream_for_the_channel = channelShell.getOutputStream();
    InputStream outputstream_from_the_channel = channelShell.getInputStream();

    BufferedReader reader = new BufferedReader(new InputStreamReader(outputstream_from_the_channel));
    PrintStream commander = new PrintStream(inputstream_for_the_channel, true);

    channelShell.connect();

    if (!commands.get(0).equals("show system information | match \"System Name\"")) {
        commands.add(0, "show system information | match \"System Name\"");
    }

    String readString = "";
    String line;
    int index = 0;

    for (String cmd : commands) {
        System.out.println(cmd);

        commander.println(cmd);
        try {
            Thread.sleep(commandsSleep);
        } catch (Exception ee) {
        }

        while ((line = reader.readLine()) != null)
        {
            if (cmd.equals("admin display-config")) {
                commander.println("");
            }

            GuiApp.textAreaLog.append("\n"+ ++index + " : " + line);
            System.out.println(index + " : " + line);
            readString += (line+"\n");
        }

    }

    if (routerType.equals("nokia")) {
        commander.println("logout");
        System.out.println("logout");
        try {
            Thread.sleep(commandsSleep);
        } catch (Exception ee) {
        }
    } else if (routerType.equals("linux")){
        commander.println("exit");
    }

    commander.close();
    channelShell.disconnect();

    try {
        Thread.sleep(commandsSleep);
    } catch (Exception ee) {
    }

    return readString;
</code>```

In the part:

```<code>    while ((line = reader.readLine()) != null)
    {
        if (cmd.equals("admin display-config")) {
            commander.println("");
        }

        GuiApp.textAreaLog.append("\n"+ ++index + " : " + line);
        System.out.println(index + " : " + line);
        readString += (line+"\n");
    }
</code>```

Is where I tried to implement a While loop to read the reader until its null, and to add to the commander a printl with "" to try to scroll this problematic command further down.

答:
What I managed to do was to insert a timelimiter to the readbuffer.</p>

```<code>for (String cmd : commands) {
    GuiApp.textAreaLog.append("\n"+"Running Command : " + cmd);
    commander.println(cmd);
    System.out.println(cmd);
    if (cmd.equals("admin display-config")) {
        commandDelay = commandsSleep*10;
    }else{
        commandDelay = commandsSleep;
    }
    line = reader.readLine();
    while (line!=null)
    {

        System.out.println(++index + " : " + line);
        readString += (line+"\n");
        try {
            line = timeLimiter.callWithTimeout(reader::readLine, commandsSleep, TimeUnit.MILLISECONDS, true);
        } catch (Exception e) {
            e.printStackTrace();
            break;
        }
    }
    try {
        Thread.sleep(commandDelay);
    } catch (Exception e) {
        //e.printStackTrace();
    }
    GuiApp.textAreaLog.append("\n"+"Comando executado com sucesso");
}
</code>```

Title: Auto Scroll Down a shell usin jsch

Body:
I am facing a problem in Java jsch. I have opened a Shell channel and I have a list of commands that I want to execute and read from the shell.

But in that commands list, there's one command that needs to be scrolled down in the shell to be shown until its end.

I am strugling to implement this auto-scroller for that command.

In my code What I did:

    ChannelShell channelShell = (ChannelShell) session.openChannel("shell");
    OutputStream inputstream_for_the_channel = channelShell.getOutputStream();
    InputStream outputstream_from_the_channel = channelShell.getInputStream();

    BufferedReader reader = new BufferedReader(new InputStreamReader(outputstream_from_the_channel));
    PrintStream commander = new PrintStream(inputstream_for_the_channel, true);

    channelShell.connect();

    if (!commands.get(0).equals("show system information | match \"System Name\"")) {
        commands.add(0, "show system information | match \"System Name\"");
    }

    String readString = "";
    String line;
    int index = 0;

    for (String cmd : commands) {
        System.out.println(cmd);

        commander.println(cmd);
        try {
            Thread.sleep(commandsSleep);
        } catch (Exception ee) {
        }

        while ((line = reader.readLine()) != null)
        {
            if (cmd.equals("admin display-config")) {
                commander.println("");
            }

            GuiApp.textAreaLog.append("\n"+ ++index + " : " + line);
            System.out.println(index + " : " + line);
            readString += (line+"\n");
        }

    }

    if (routerType.equals("nokia")) {
        commander.println("logout");
        System.out.println("logout");
        try {
            Thread.sleep(commandsSleep);
        } catch (Exception ee) {
        }
    } else if (routerType.equals("linux")){
        commander.println("exit");
    }

    commander.close();
    channelShell.disconnect();

    try {
        Thread.sleep(commandsSleep);
    } catch (Exception ee) {
    }

    return readString;

In the part:

    while ((line = reader.readLine()) != null)
    {
        if (cmd.equals("admin display-config")) {
            commander.println("");
        }

        GuiApp.textAreaLog.append("\n"+ ++index + " : " + line);
        System.out.println(index + " : " + line);
        readString += (line+"\n");
    }

Is where I tried to implement a While loop to read the reader until its null, and to add to the commander a printl with "" to try to scroll this problematic command further down.

Body:
What I managed to do was to insert a timelimiter to the readbuffer.

for (String cmd : commands) {
    GuiApp.textAreaLog.append("\n"+"Running Command : " + cmd);
    commander.println(cmd);
    System.out.println(cmd);
    if (cmd.equals("admin display-config")) {
        commandDelay = commandsSleep*10;
    }else{
        commandDelay = commandsSleep;
    }
    line = reader.readLine();
    while (line!=null)
    {

        System.out.println(++index + " : " + line);
        readString += (line+"\n");
        try {
            line = timeLimiter.callWithTimeout(reader::readLine, commandsSleep, TimeUnit.MILLISECONDS, true);
        } catch (Exception e) {
            e.printStackTrace();
            break;
        }
    }
    try {
        Thread.sleep(commandDelay);
    } catch (Exception e) {
        //e.printStackTrace();
    }
    GuiApp.textAreaLog.append("\n"+"Comando executado com sucesso");
}


问:
Oracle 18c - ERROR CREATING MATERIALIZED VIEW - ORA-00933
I tried to create a materialized view on a oracle 18c and I got a ORA-00933.

```<code>CREATE MATERIALIZED VIEW Top10Cancelacion
BUILD IMMEDIATE
REFRESH ON DEMAND
AS SELECT idAeropuerto
FROM aeropuerto
ORDER BY (  SELECT count(*)
            FROM vuelo v JOIN incidencia i
                ON v.idVuelo = i.idVuelo
            WHERE (idAeropuerto = v.origen OR
                    idAeropuerto = v.destino) AND
                i.tipo = 'Cancelado'
        )/( SELECT count(*) FROM vuelo )
    DESC
FETCH FIRST 10 ROWS ONLY;
</code>```

I have tried deleting the FETCH FIRST line and the ORDER BY, but I have the same error. I have tried to executing the query and it works without problem. Despite that, this is my database structure of the important parts:

```<code>CREATE TABLE Aeropuerto(
        idAeropuerto    VARCHAR2(4),
        nombre          VARCHAR2(100),
        ciudad          VARCHAR2(100),
        estado          VARCHAR2(100),
        pais            VARCHAR2(100),
        latitud         DECIMAL(11,8),
        longitud        DECIMAL(11,8),
        PRIMARY KEY (idAeropuerto)
);
CREATE TABLE Vuelo(
    idVuelo         NUMBER,
    origen          VARCHAR2(4),
    destino         VARCHAR2(4),
    avion           VARCHAR2(10),
    tiempoOrigen    TIMESTAMP,
    tiempoDestino   TIMESTAMP,
    duracion        NUMBER,
    distancia       NUMBER,
    PRIMARY KEY (idVuelo),
    FOREIGN KEY (origen) REFERENCES Aeropuerto(idAeropuerto) ON DELETE CASCADE,
    FOREIGN KEY (destino) REFERENCES Aeropuerto(idAeropuerto) ON DELETE CASCADE,
    FOREIGN KEY (avion) REFERENCES Avion(idAvion) ON DELETE CASCADE,
    CONSTRAINT distinct_places CHECK (origen != destino)
);
CREATE TABLE Incidencia(
    idVuelo NUMBER,
    tipo    VARCHAR2(100),
    detalles VARCHAR2(100),
    PRIMARY KEY (idVuelo, tipo),
    FOREIGN KEY (idVuelo) REFERENCES Vuelo(idVuelo) ON DELETE CASCADE
);
</code>```

Is there something I haven't seen? Thank you in advance

答:
Looks like an old syntax parser bug. Wrap the query in parenthesis, like this:</p>

```<code>SQL> CREATE MATERIALIZED VIEW Top10Cancelacion
BUILD IMMEDIATE
REFRESH ON DEMAND
AS (SELECT idAeropuerto
FROM aeropuerto
ORDER BY (  SELECT count(*)
            FROM vuelo v JOIN incidencia i
                ON v.idVuelo = i.idVuelo
            WHERE (idAeropuerto = v.origen OR
                    idAeropuerto = v.destino) AND
                i.tipo = 'Cancelado'
        )/( SELECT count(*) FROM vuelo )
    DESC
FETCH FIRST 10 ROWS ONLY);

Materialized view created.
</code>```

Body:
I tried to create a materialized view on a oracle 18c and I got a ORA-00933.

CREATE MATERIALIZED VIEW Top10Cancelacion
BUILD IMMEDIATE
REFRESH ON DEMAND
AS SELECT idAeropuerto
FROM aeropuerto
ORDER BY (  SELECT count(*)
            FROM vuelo v JOIN incidencia i
                ON v.idVuelo = i.idVuelo
            WHERE (idAeropuerto = v.origen OR
                    idAeropuerto = v.destino) AND
                i.tipo = 'Cancelado'
        )/( SELECT count(*) FROM vuelo )
    DESC
FETCH FIRST 10 ROWS ONLY;

I have tried deleting the FETCH FIRST line and the ORDER BY, but I have the same error. I have tried to executing the query and it works without problem. Despite that, this is my database structure of the important parts:

CREATE TABLE Aeropuerto(
        idAeropuerto    VARCHAR2(4),
        nombre          VARCHAR2(100),
        ciudad          VARCHAR2(100),
        estado          VARCHAR2(100),
        pais            VARCHAR2(100),
        latitud         DECIMAL(11,8),
        longitud        DECIMAL(11,8),
        PRIMARY KEY (idAeropuerto)
);
CREATE TABLE Vuelo(
    idVuelo         NUMBER,
    origen          VARCHAR2(4),
    destino         VARCHAR2(4),
    avion           VARCHAR2(10),
    tiempoOrigen    TIMESTAMP,
    tiempoDestino   TIMESTAMP,
    duracion        NUMBER,
    distancia       NUMBER,
    PRIMARY KEY (idVuelo),
    FOREIGN KEY (origen) REFERENCES Aeropuerto(idAeropuerto) ON DELETE CASCADE,
    FOREIGN KEY (destino) REFERENCES Aeropuerto(idAeropuerto) ON DELETE CASCADE,
    FOREIGN KEY (avion) REFERENCES Avion(idAvion) ON DELETE CASCADE,
    CONSTRAINT distinct_places CHECK (origen != destino)
);
CREATE TABLE Incidencia(
    idVuelo NUMBER,
    tipo    VARCHAR2(100),
    detalles VARCHAR2(100),
    PRIMARY KEY (idVuelo, tipo),
    FOREIGN KEY (idVuelo) REFERENCES Vuelo(idVuelo) ON DELETE CASCADE
);

Is there something I haven't seen? Thank you in advance

Body:
Looks like an old syntax parser bug. Wrap the query in parenthesis, like this:

SQL> CREATE MATERIALIZED VIEW Top10Cancelacion
BUILD IMMEDIATE
REFRESH ON DEMAND
AS (SELECT idAeropuerto
FROM aeropuerto
ORDER BY (  SELECT count(*)
            FROM vuelo v JOIN incidencia i
                ON v.idVuelo = i.idVuelo
            WHERE (idAeropuerto = v.origen OR
                    idAeropuerto = v.destino) AND
                i.tipo = 'Cancelado'
        )/( SELECT count(*) FROM vuelo )
    DESC
FETCH FIRST 10 ROWS ONLY);

Materialized view created.


问:
List files in the listbox like windows explorer in Delphi
I'm listing files from a certain directory, but the listing is not the same as Windows Explorer, even if I check Sorted.

答:
You need to custom-sort the strings with a sort algorithm called "LogicalCompare".
Ingredients follow, (I hope I understand how to add code...). Also, this works in delphi10.3, don't know about previous versions.

```<code>uses Winapi.ShLwApi;
function LogicalCompare(List: TStringList; Index1, Index2: integer): integer;
begin
  Result := StrCmpLogicalW(PWideChar(List[Index1]), PWideChar(List[Index2]));
end;
</code>```

For your listbox-items you need a bit of a kludge, since items are of type TStrings, and Customsort only works for TStringlist. After the FindFirst etc. is finished add the
following:

```<code>...
var sl: TStringlist;
....//Listbox1 items are populated
sl:=TStringlist.create;
try
  sl.assign(Listbox1.items);
  sl.Customsort(LogicalCompare);
  Listbox1.items.assign(sl);
finally
  sl.free;
end;
....
</code>```

Body:
You need to custom-sort the strings with a sort algorithm called "LogicalCompare".
Ingredients follow, (I hope I understand how to add code...). Also, this works in delphi10.3, don't know about previous versions.

uses Winapi.ShLwApi;
function LogicalCompare(List: TStringList; Index1, Index2: integer): integer;
begin
  Result := StrCmpLogicalW(PWideChar(List[Index1]), PWideChar(List[Index2]));
end;

For your listbox-items you need a bit of a kludge, since items are of type TStrings, and Customsort only works for TStringlist. After the FindFirst etc. is finished add the
following:

...
var sl: TStringlist;
....//Listbox1 items are populated
sl:=TStringlist.create;
try
  sl.assign(Listbox1.items);
  sl.Customsort(LogicalCompare);
  Listbox1.items.assign(sl);
finally
  sl.free;
end;
....


问:
Targeting one specific value based off index
I'm using jQuery to populate a standard HTML select list from a JSON file. The populate function works fine, but now I need to target a specific value of whatever dropdown is selected to get a value. The .0xx AFM is what goes in the dropdown box, the value is the value that's assigned to the select element, and the price is the price associated with that dropdown. What I'm trying to achieve is use jQuery or JS to get the price associated with the selected dropdown. That way I can use the price value as a variable in a calculation formula.

答:
You can find the price each time a value is selected from the list. I can't edit your code because it is a screenshot, but this would go INSIDE the get getJSON call but AFTER the each loop.

Something like:

// inside your getJson call, after your $.each loop

$(dropdown).on('change', function() {
  const selectedValue = $(this).val();
  const match = Object.values(data).find(entry => entry.value === selectedValue);
  console.log(match && match.price);
});```


问:
Bootstrap vue: form-group label styling
I am trying t style label for form-group in bootstrap vue, but it's not working. I have try everything but no luck. I could really need some help how to do this.

.add-style label {

color: red;

}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><b-container>

<b-form-group class="add-style" label="Product Name">
          <b-form-input type="text" id="pName" required
                        placeholder="Enter product name"/>
        </b-form-group>

</b-container></code>```

答:
The thing is if you are using css you must use either selector (class or id) or the tag elements not both. You are using both i.e. .add-style label. Here .add-style is a class and label is a tag element.

Also there has to be some text inside your  markup to see the effect. I have used simple text. You can replace with your own vue text(or whatever you call in your language for e.g. {page.Title}) as per your requirement:

.add-style{

color: red;

}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><b-container>

<b-form-group class="add-style" label="Product Name">
          <b-form-input type="text" id="pName" required
                        placeholder="Enter product name"/>
                  test
        </b-form-group>

</b-container></code>```

Hope this helps.

Title: Bootstrap vue: form-group label styling

Body:
The thing is if you are using css you must use either selector (class or id) or the tag elements not both. You are using both i.e. .add-style label. Here .add-style is a class and label is a tag element.

Also there has to be some text inside your  markup to see the effect. I have used simple text. You can replace with your own vue text(or whatever you call in your language for e.g. {page.Title}) as per your requirement:

.add-style{

color: red;

}

<b-container>

<b-form-group class="add-style" label="Product Name">
          <b-form-input type="text" id="pName" required
                        placeholder="Enter product name"/>
                  test
        </b-form-group>

</b-container>

Hope this helps.


问:
accessing the return value of function that was bound to an event (tkinter)
Basically, what I've done is bound a click event to a function.  For example:

```<code>self.button1.bind("<Button-1>",self.chooseDice)
</code>```

What I want now is to access the result of chooseDice() in another function.  What is the best way to go about doing that?

```<code>class GraphicsInterface:

    #we want to initialize the game board here, set up the dice and buttons
    def __init__(self):
        self.window = Tk()
        self.window.geometry("720x500")

        #buttons under each die
        self.clicked=[] #empty list to collect all the buttons that were clicked (see chooseDice function)
        self.button1 = Button(self.window, text="Dice 1", width=13) #create the button object
        self.button1.place(x=60, y=160)
        #bind button click event to a function (chooseDice())
        self.button1.bind("<Button-1>",self.chooseDice)

        self.button2 = Button(self.window, text="Dice 2", width=13)
        self.button2.place(x=185, y=160)
        self.button2.bind("<Button-1>",self.chooseDice)

    #using the event as an argument, append the text to the clicked list
    def chooseDice(self, event):
        self.clicked.append(event.widget.cget('text'))
        self.diceList=[] #create a new empty list
        for i in range(len(self.clicked)):
            self.diceList.append(int(self.clicked[i][5])) #get just the int value of the last character (i.e. the dice number)
        self.deactivate(event.widget)  #deactivate the button
        return self.diceList
</code>```

答:
Refactor.  Split this into two functions.

One returns the proper result, usable by other objects.

The other is bound to a GUI control, and uses the proper result to activate and deactivate GUI objects.

Indeed, you should always do this.  You should always have functions that do normal Python stuff, work correctly without the GUI and can be unit tested without the GUI.  Then you connect this working "model" to the GUI.

Body:
Basically, what I've done is bound a click event to a function.  For example:

self.button1.bind("<Button-1>",self.chooseDice)

What I want now is to access the result of chooseDice() in another function.  What is the best way to go about doing that?

class GraphicsInterface:

    #we want to initialize the game board here, set up the dice and buttons
    def __init__(self):
        self.window = Tk()
        self.window.geometry("720x500")

        #buttons under each die
        self.clicked=[] #empty list to collect all the buttons that were clicked (see chooseDice function)
        self.button1 = Button(self.window, text="Dice 1", width=13) #create the button object
        self.button1.place(x=60, y=160)
        #bind button click event to a function (chooseDice())
        self.button1.bind("<Button-1>",self.chooseDice)

        self.button2 = Button(self.window, text="Dice 2", width=13)
        self.button2.place(x=185, y=160)
        self.button2.bind("<Button-1>",self.chooseDice)

    #using the event as an argument, append the text to the clicked list
    def chooseDice(self, event):
        self.clicked.append(event.widget.cget('text'))
        self.diceList=[] #create a new empty list
        for i in range(len(self.clicked)):
            self.diceList.append(int(self.clicked[i][5])) #get just the int value of the last character (i.e. the dice number)
        self.deactivate(event.widget)  #deactivate the button
        return self.diceList


问:
How to handle click event from a Fragment, produces error Nullpointer exception, trying to invoke *setOnClickListener* from a null object reference
Please, i have been trying to handle click event from my project and haven't actually found a place to actually put the button.setOnClickListener(handler); statement. The truth is that i have a ViewPager inside another layout.xml file which i inflated from within a Fragment. But i have two other layout files, which i used to provide content for the ViewPager itself, which i did and it worked properly. But when i tried to handle onClick event from within any of my classes, it produces a NullPointer Exception. This is my first project on Android and i can't seem to find any solution even on StackOverflow, because none of the answers really solved my problem. I will really appreciate if someone could read through this long code and provide an answer to my problem. Thanks in advance. It's a Calculator App

Code below

```    *In MainActivity.java*

        package com.projects.calculatorapp2;

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

    public class MainActivity extends FragmentActivity {

       @Override
        public void onCreate(Bundle savedState){
           super.onCreate(savedState);
           getSupportFragmentManager()
                   .beginTransaction()
                   .add(android.R.id.content, new ViewPagerFragment())
                   .commit();

       }
    }

    *In ViewPagerFragment.java*

    package com.projects.calculatorapp2;

    import android.os.Bundle;
    import android.support.annotation.NonNull;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.support.v4.view.ViewPager;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.EditText;

    /**
     *
Description

     * A simple {@link Fragment} subclass that provides view for the main activity.
     * @author Noah
     * @since 2020
     *
     */
    public class ViewPagerFragment extends Fragment implements View.OnClickListener {

        EditText input;
        protected ViewPager pager;
        public StringBuilder builderText = new StringBuilder();

        @Override
        public void onCreate(Bundle state) {
            super.onCreate(state);

        }

        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View view = inflater.inflate(R.layout.activity_main, container, false);
            pager = view.findViewById(R.id.pager);
            input = view.findViewById(R.id.edit);

            pager.setAdapter(new ButtonAdapter(getFragmentManager()));
            return (view);

        }

     @Override
    public void onViewCreated(@NonNull View view, Bundle savedState){
        Button one = view.findViewById(R.id.seven);
        one.setOnClickListener(this);
    }
        @Override
        public void onClick(View view) {
            int buttonId = view.getId();

            switch (buttonId) {

                case R.id.one: {
                    builderText.append(1);
                    Log.d(getClass().getSimpleName(), String.valueOf(builderText));
                    input.setText(builderText);
                }
            }
        }

        private class ButtonAdapter extends FragmentPagerAdapter {

            // default constructor chained to superclass
            ButtonAdapter(FragmentManager fm) {
                super(fm);
            }

            @Override
            public int getCount() {
                return 2; //number of pages
            }

            @Override
            public Fragment getItem(int position) {
    //            Log.d(getClass().getSimpleName(), String.valueOf(position));
                return (ButtonSet.newInstance(position));
            }
        }
    }

     *In ButtonSet.java*

        package com.projects.calculatorapp2;

        import android.os.Bundle;
        import android.support.annotation.NonNull;
        import android.support.v4.app.Fragment;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;

        public class ButtonSet extends Fragment {

            public static final String POS_KEY = "position";

            static ButtonSet newInstance(int pos){

                ButtonSet bs = new ButtonSet();
                Bundle bundle = new Bundle();
                bundle.putInt(POS_KEY, pos);
                bs.setArguments(bundle);
                return (bs);
            }

            @Override
            public View onCreateView(@NonNull LayoutInflater inflater,
                                     ViewGroup container,
                                     Bundle state) {

                //noinspection ConstantConditions
                if(getArguments().getInt(POS_KEY) == 0)
                    return inflater.inflate(R.layout.content_1,
                            container, false);

                return inflater.inflate(R.layout.content_2,
                        container, false);

            }

        }

     *In activity_main.xml* (Main layout file when app is lauched)

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical">

            <EditText
                android:id="@id/edit"
                android:textIsSelectable="true"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:inputType="text"
                android:textSize="40sp"
                android:background="@android:color/transparent"
                tools:ignore="Autofill,LabelFor"
                android:hint="@string/ediText_hint"
                android:gravity="center_vertical|end"

                />

          <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
              <Button
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="0dp"
                  android:layout_marginEnd="110dp"
                  android:layout_marginRight="70dp"
                  android:background="@color/black"
                  android:clickable="false" />

              <Button
                  android:id="@id/c_button"
                  android:layout_width="100dp"
                  android:layout_height="wrap_content"
                  android:layout_alignParentEnd="true"
                  android:layout_alignParentRight="true"
                  android:layout_marginStart="3dp"
                  android:layout_marginLeft="3dp"
                  android:textColor="@color/white"
                  android:textSize="20sp"
                  android:text="@string/delete"
                  android:background="@color/dark_red"/>

          </RelativeLayout>

            <android.support.v4.view.ViewPager
                android:id="@id/pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </LinearLayout>

*In content_1.xml* (This is first content of ViewPager)

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        tools:context="com.projects.calculatorapp2.ViewPagerFragment">

        <Button
            android:id="@id/seven"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/seven"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintWidth_percent="25"
            app:layout_constraintEnd_toStartOf="@+id/eight"
            app:layout_constraintRight_toLeftOf="@id/eight"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="@id/four"
            app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@id/eight"
                style="@android:style/Widget.Button"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintWidth_percent="0.25"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toLeftOf="@id/nine"
                app:layout_constraintBottom_toTopOf="@id/five"
                tools:ignore="ButtonStyle"
                android:textSize="50sp"
                android:typeface="serif"
                android:text="@string/eight"/>

            <Button
                android:id="@id/nine"
                style="@android:style/Widget.Button"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintWidth_percent="0.25"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toLeftOf="@id/divide"
                app:layout_constraintBottom_toTopOf="@id/six"
                tools:ignore="ButtonStyle"
                android:textSize="50sp"
                android:typeface="serif"
                android:text="@string/nine"/>

            <Button
                android:id="@id/divide"
                style="@android:style/Widget.Button"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintWidth_percent="0.25"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toTopOf="@id/times"
                tools:ignore="ButtonStyle"
                android:textSize="50sp"
                android:typeface="serif"
                android:text="@string/divide" />

        <Button
            android:id="@id/four"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@id/seven"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toTopOf="@id/one"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/four" />

        <Button
            android:id="@id/five"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@id/eight"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/four"
            app:layout_constraintBottom_toTopOf="@id/two"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/five" />

        <Button
            android:id="@id/six"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/nine"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/five"
            app:layout_constraintBottom_toTopOf="@id/three"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/six" />

        <Button
            android:id="@id/times"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/divide"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/six"
            app:layout_constraintBottom_toTopOf="@id/minus"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="normal"
            android:text="@string/times" />

        <Button
            android:id="@+id/one"

            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/four"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintBottom_toTopOf="@id/decimal"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/one" />

        <Button
            android:id="@id/two"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/five"
            app:layout_constraintStart_toEndOf="@+id/one"
            app:layout_constraintBottom_toTopOf="@id/zero"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/two" />

        <Button
            android:id="@id/three"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/times"
            app:layout_constraintStart_toEndOf="@+id/two"
            app:layout_constraintBottom_toTopOf="@id/equals"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/three" />

        <Button
            android:id="@id/minus"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/times"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/three"
            app:layout_constraintBottom_toTopOf="@id/add"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/minus" />

        <Button
            android:id="@id/decimal"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/one"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/decimal" />

        <Button
            android:id="@id/zero"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/two"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/decimal"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/zero" />

        <Button
            android:id="@id/equals"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/three"
            app:layout_constraintStart_toEndOf="@+id/zero"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/equals" />

        <Button
            android:id="@id/add"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/minus"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/add" />

    </android.support.constraint.ConstraintLayout>

*In content_2.xml* (Second content of ViewPager)

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto">

        <Button
            android:id="@id/sin"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/sin"
            android:textSize="50sp"
            android:typeface="serif"

            app:layout_constraintBottom_toTopOf="@+id/log"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintWidth_percent="0.33"
            />

        <Button
            android:id="@id/cos"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/cos"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@+id/sin"
            app:layout_constraintEnd_toStartOf="@+id/tan"
            app:layout_constraintBottom_toTopOf="@+id/log10"
            app:layout_constraintWidth_percent="0.33"

            />

        <Button
            android:id="@id/tan"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/tan"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintBottom_toTopOf="@+id/factorial"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintWidth_percent="0.33"/>

        <Button
            android:id="@id/log"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/log"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintBottom_toTopOf="@+id/pi"
            app:layout_constraintTop_toBottomOf="@id/sin"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintWidth_percent="0.33"
            />

        <Button
            android:id="@id/log10"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/log10"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/cos"
            app:layout_constraintStart_toEndOf="@+id/log"
            app:layout_constraintEnd_toStartOf="@+id/tan"
            app:layout_constraintBottom_toTopOf="@+id/exp"
            app:layout_constraintWidth_percent="0.33"
            />

        <Button
            android:id="@id/factorial"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/factorial"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/tan"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintBottom_toTopOf="@+id/pow"/>

        <Button
            android:id="@id/pi"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/pi"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/log"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintBottom_toBottomOf="parent"
            />

        <Button
            android:id="@id/exp"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/exp"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/log10"
            app:layout_constraintStart_toEndOf="@+id/pi"
            app:layout_constraintEnd_toStartOf="@+id/tan"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintBottom_toBottomOf="parent"
            />

        <Button
            android:id="@id/pow"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/pow"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/factorial"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintBottom_toBottomOf="parent"/>
    </android.support.constraint.ConstraintLayout>
```

Log message

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
        at com.projects.calculatorapp2.ViewPagerFragment.onViewCreated(ViewPagerFragment.java:57)

答:
Override the onViewCreated() in your fragment and you can set your click listeners in that method.

Also I see an issue in your ids. It should be like

```<code>android:id="@+id/seven"
</code>```

Notice the + sign

Detailed
Make your fragment having the button implement View.OnClickListener

Then override the onViewCreated method. Inside it do something like this for every button:

```<code>yourButton = view.findViewById(R.id.seven);
yourButton.setOnClickListener(this);
</code>```

Do the same for all buttons

Edit:
Override the onViewCreated method in your ButtonSet fragment and also put a position check like this:

```<code>//inside onViewCreated
if(position == 0) {
    //init buttons from content 1 xml layout, and set listeners
} else {
    //init buttons from content 2 layout
}

</code>```

Body:
Please, i have been trying to handle click event from my project and haven't actually found a place to actually put the button.setOnClickListener(handler); statement. The truth is that i have a ViewPager inside another layout.xml file which i inflated from within a Fragment. But i have two other layout files, which i used to provide content for the ViewPager itself, which i did and it worked properly. But when i tried to handle onClick event from within any of my classes, it produces a NullPointer Exception. This is my first project on Android and i can't seem to find any solution even on StackOverflow, because none of the answers really solved my problem. I will really appreciate if someone could read through this long code and provide an answer to my problem. Thanks in advance. It's a Calculator App

Code below

    *In MainActivity.java*

        package com.projects.calculatorapp2;

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

    public class MainActivity extends FragmentActivity {

       @Override
        public void onCreate(Bundle savedState){
           super.onCreate(savedState);
           getSupportFragmentManager()
                   .beginTransaction()
                   .add(android.R.id.content, new ViewPagerFragment())
                   .commit();

       }
    }

    *In ViewPagerFragment.java*

    package com.projects.calculatorapp2;

    import android.os.Bundle;
    import android.support.annotation.NonNull;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.support.v4.view.ViewPager;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.EditText;

    /**
     *
Description

     * A simple {@link Fragment} subclass that provides view for the main activity.
     * @author Noah
     * @since 2020
     *
     */
    public class ViewPagerFragment extends Fragment implements View.OnClickListener {

        EditText input;
        protected ViewPager pager;
        public StringBuilder builderText = new StringBuilder();

        @Override
        public void onCreate(Bundle state) {
            super.onCreate(state);

        }

        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View view = inflater.inflate(R.layout.activity_main, container, false);
            pager = view.findViewById(R.id.pager);
            input = view.findViewById(R.id.edit);

            pager.setAdapter(new ButtonAdapter(getFragmentManager()));
            return (view);

        }

     @Override
    public void onViewCreated(@NonNull View view, Bundle savedState){
        Button one = view.findViewById(R.id.seven);
        one.setOnClickListener(this);
    }
        @Override
        public void onClick(View view) {
            int buttonId = view.getId();

            switch (buttonId) {

                case R.id.one: {
                    builderText.append(1);
                    Log.d(getClass().getSimpleName(), String.valueOf(builderText));
                    input.setText(builderText);
                }
            }
        }

        private class ButtonAdapter extends FragmentPagerAdapter {

            // default constructor chained to superclass
            ButtonAdapter(FragmentManager fm) {
                super(fm);
            }

            @Override
            public int getCount() {
                return 2; //number of pages
            }

            @Override
            public Fragment getItem(int position) {
    //            Log.d(getClass().getSimpleName(), String.valueOf(position));
                return (ButtonSet.newInstance(position));
            }
        }
    }

     *In ButtonSet.java*

        package com.projects.calculatorapp2;

        import android.os.Bundle;
        import android.support.annotation.NonNull;
        import android.support.v4.app.Fragment;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;

        public class ButtonSet extends Fragment {

            public static final String POS_KEY = "position";

            static ButtonSet newInstance(int pos){

                ButtonSet bs = new ButtonSet();
                Bundle bundle = new Bundle();
                bundle.putInt(POS_KEY, pos);
                bs.setArguments(bundle);
                return (bs);
            }

            @Override
            public View onCreateView(@NonNull LayoutInflater inflater,
                                     ViewGroup container,
                                     Bundle state) {

                //noinspection ConstantConditions
                if(getArguments().getInt(POS_KEY) == 0)
                    return inflater.inflate(R.layout.content_1,
                            container, false);

                return inflater.inflate(R.layout.content_2,
                        container, false);

            }

        }

     *In activity_main.xml* (Main layout file when app is lauched)

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical">

            <EditText
                android:id="@id/edit"
                android:textIsSelectable="true"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:inputType="text"
                android:textSize="40sp"
                android:background="@android:color/transparent"
                tools:ignore="Autofill,LabelFor"
                android:hint="@string/ediText_hint"
                android:gravity="center_vertical|end"

                />

          <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
              <Button
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="0dp"
                  android:layout_marginEnd="110dp"
                  android:layout_marginRight="70dp"
                  android:background="@color/black"
                  android:clickable="false" />

              <Button
                  android:id="@id/c_button"
                  android:layout_width="100dp"
                  android:layout_height="wrap_content"
                  android:layout_alignParentEnd="true"
                  android:layout_alignParentRight="true"
                  android:layout_marginStart="3dp"
                  android:layout_marginLeft="3dp"
                  android:textColor="@color/white"
                  android:textSize="20sp"
                  android:text="@string/delete"
                  android:background="@color/dark_red"/>

          </RelativeLayout>

            <android.support.v4.view.ViewPager
                android:id="@id/pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </LinearLayout>

*In content_1.xml* (This is first content of ViewPager)

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        tools:context="com.projects.calculatorapp2.ViewPagerFragment">

        <Button
            android:id="@id/seven"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/seven"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintWidth_percent="25"
            app:layout_constraintEnd_toStartOf="@+id/eight"
            app:layout_constraintRight_toLeftOf="@id/eight"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="@id/four"
            app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@id/eight"
                style="@android:style/Widget.Button"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintWidth_percent="0.25"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toLeftOf="@id/nine"
                app:layout_constraintBottom_toTopOf="@id/five"
                tools:ignore="ButtonStyle"
                android:textSize="50sp"
                android:typeface="serif"
                android:text="@string/eight"/>

            <Button
                android:id="@id/nine"
                style="@android:style/Widget.Button"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintWidth_percent="0.25"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toLeftOf="@id/divide"
                app:layout_constraintBottom_toTopOf="@id/six"
                tools:ignore="ButtonStyle"
                android:textSize="50sp"
                android:typeface="serif"
                android:text="@string/nine"/>

            <Button
                android:id="@id/divide"
                style="@android:style/Widget.Button"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintWidth_percent="0.25"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintBottom_toTopOf="@id/times"
                tools:ignore="ButtonStyle"
                android:textSize="50sp"
                android:typeface="serif"
                android:text="@string/divide" />

        <Button
            android:id="@id/four"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@id/seven"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toTopOf="@id/one"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/four" />

        <Button
            android:id="@id/five"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@id/eight"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/four"
            app:layout_constraintBottom_toTopOf="@id/two"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/five" />

        <Button
            android:id="@id/six"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/nine"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/five"
            app:layout_constraintBottom_toTopOf="@id/three"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/six" />

        <Button
            android:id="@id/times"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/divide"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/six"
            app:layout_constraintBottom_toTopOf="@id/minus"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="normal"
            android:text="@string/times" />

        <Button
            android:id="@+id/one"

            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/four"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintBottom_toTopOf="@id/decimal"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/one" />

        <Button
            android:id="@id/two"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/five"
            app:layout_constraintStart_toEndOf="@+id/one"
            app:layout_constraintBottom_toTopOf="@id/zero"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/two" />

        <Button
            android:id="@id/three"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/times"
            app:layout_constraintStart_toEndOf="@+id/two"
            app:layout_constraintBottom_toTopOf="@id/equals"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/three" />

        <Button
            android:id="@id/minus"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/times"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/three"
            app:layout_constraintBottom_toTopOf="@id/add"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/minus" />

        <Button
            android:id="@id/decimal"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/one"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/decimal" />

        <Button
            android:id="@id/zero"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/two"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toEndOf="@+id/decimal"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/zero" />

        <Button
            android:id="@id/equals"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/three"
            app:layout_constraintStart_toEndOf="@+id/zero"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/equals" />

        <Button
            android:id="@id/add"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintWidth_percent="0.25"
            app:layout_constraintTop_toBottomOf="@+id/minus"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:ignore="ButtonStyle"
            android:textSize="50sp"
            android:typeface="serif"
            android:text="@string/add" />

    </android.support.constraint.ConstraintLayout>

*In content_2.xml* (Second content of ViewPager)

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto">

        <Button
            android:id="@id/sin"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/sin"
            android:textSize="50sp"
            android:typeface="serif"

            app:layout_constraintBottom_toTopOf="@+id/log"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintWidth_percent="0.33"
            />

        <Button
            android:id="@id/cos"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/cos"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@+id/sin"
            app:layout_constraintEnd_toStartOf="@+id/tan"
            app:layout_constraintBottom_toTopOf="@+id/log10"
            app:layout_constraintWidth_percent="0.33"

            />

        <Button
            android:id="@id/tan"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/tan"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintBottom_toTopOf="@+id/factorial"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintWidth_percent="0.33"/>

        <Button
            android:id="@id/log"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/log"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintBottom_toTopOf="@+id/pi"
            app:layout_constraintTop_toBottomOf="@id/sin"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintWidth_percent="0.33"
            />

        <Button
            android:id="@id/log10"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/log10"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/cos"
            app:layout_constraintStart_toEndOf="@+id/log"
            app:layout_constraintEnd_toStartOf="@+id/tan"
            app:layout_constraintBottom_toTopOf="@+id/exp"
            app:layout_constraintWidth_percent="0.33"
            />

        <Button
            android:id="@id/factorial"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/factorial"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/tan"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintBottom_toTopOf="@+id/pow"/>

        <Button
            android:id="@id/pi"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/pi"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/log"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintBottom_toBottomOf="parent"
            />

        <Button
            android:id="@id/exp"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/exp"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/log10"
            app:layout_constraintStart_toEndOf="@+id/pi"
            app:layout_constraintEnd_toStartOf="@+id/tan"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintBottom_toBottomOf="parent"
            />

        <Button
            android:id="@id/pow"
            style="@android:style/Widget.Button"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:text="@string/pow"
            android:textSize="50sp"
            android:typeface="serif"
            app:layout_constraintTop_toBottomOf="@id/factorial"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintWidth_percent="0.33"
            app:layout_constraintBottom_toBottomOf="parent"/>
    </android.support.constraint.ConstraintLayout>

Log message

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
        at com.projects.calculatorapp2.ViewPagerFragment.onViewCreated(ViewPagerFragment.java:57)

Body:
Override the onViewCreated() in your fragment and you can set your click listeners in that method.

Also I see an issue in your ids. It should be like

android:id="@+id/seven"

Notice the + sign

Detailed
Make your fragment having the button implement View.OnClickListener

Then override the onViewCreated method. Inside it do something like this for every button:

yourButton = view.findViewById(R.id.seven);
yourButton.setOnClickListener(this);

Do the same for all buttons

Edit:
Override the onViewCreated method in your ButtonSet fragment and also put a position check like this:

//inside onViewCreated
if(position == 0) {
    //init buttons from content 1 xml layout, and set listeners
} else {
    //init buttons from content 2 layout
}


问:
How to create tun interface inside Docker container image?
I'm trying to create a Docker image with a /dev/net/tun device so that the image can be used across Linux, Mac and Windows host machines. The device does not need access to the host's network interface.

Note that passing --device /dev/net/tun:/dev/net/tun to docker run is undesirable because this only works on Linux.

Once the container is started, I can manually add the device by running:

```<code>$ sudo mkdir /dev/net
$ sudo mknod /dev/net/tun c 10 200
$ sudo ip tuntap add mode tap tap
</code>```

but when I add these lines to the Dockerfile it results in an error:

```<code>Step 35/46 : RUN mkdir /dev/net
 ---> Running in 5475f2e4b778
Removing intermediate container 5475f2e4b778
 ---> c6f8e2998e1a
Step 36/46 : RUN mknod /dev/net/tun c 10 200
 ---> Running in fdb0ed813cdb
mknod: /dev/net/tun: No such file or directory
The command '/bin/sh -c mknod /dev/net/tun c 10 200' returned a non-zero code: 1
</code>```

I believe the crux here is creating a filesystem node from within a docker build step? Is this possible?

答:
The /dev directory is special, and Docker build steps cannot really put anything there.  That also is mentioned in an answer to question 56346114.

Apparently a device in /dev isn't a file with data in it, but a placeholder, an address, a pointer, a link to driver code in memory that does something when accessed.  Such driver code in memory is not something that a Docker image would hold.

I got device creation working in a container by putting your command line code in an .sh script wrapping the app we really want to run.

Body:
I'm trying to create a Docker image with a /dev/net/tun device so that the image can be used across Linux, Mac and Windows host machines. The device does not need access to the host's network interface.

Note that passing --device /dev/net/tun:/dev/net/tun to docker run is undesirable because this only works on Linux.

Once the container is started, I can manually add the device by running:

$ sudo mkdir /dev/net
$ sudo mknod /dev/net/tun c 10 200
$ sudo ip tuntap add mode tap tap

but when I add these lines to the Dockerfile it results in an error:

Step 35/46 : RUN mkdir /dev/net
 ---> Running in 5475f2e4b778
Removing intermediate container 5475f2e4b778
 ---> c6f8e2998e1a
Step 36/46 : RUN mknod /dev/net/tun c 10 200
 ---> Running in fdb0ed813cdb
mknod: /dev/net/tun: No such file or directory
The command '/bin/sh -c mknod /dev/net/tun c 10 200' returned a non-zero code: 1

I believe the crux here is creating a filesystem node from within a docker build step? Is this possible?


问:
Iterate matrix of vectors using c++ with auto range and structured binding?
I want to do something like this:

```<code>vector<vector<int>>& matrix; -> [[1, 1], [2, 2]]

for (auto [a, b] : matrix) {
    ...
}
</code>```

This won't compile for me. Is this the correct way to do this? If not why?

答:
The above approach is only valid for iterating over the map in C++. If d is unordered map then it can be iterated through the below code

```<code>for(auto& [a,b] : d)
{
    count<< "First" << a.first << "Second" << a.second <<endl;
}
</code>```

To iterate over the vector> matrix as in this case the below code can be used,

```<code>vector<vector<int>> mat = { {1,1},{2,2} };
for (auto& a : mat) {
  for (auto& b : a) {
    cout << b << " ";
  }
  cout <<endl;
}
</code>```

Body:
I want to do something like this:

vector<vector<int>>& matrix; -> [[1, 1], [2, 2]]

for (auto [a, b] : matrix) {
    ...
}

This won't compile for me. Is this the correct way to do this? If not why?

Body:
The above approach is only valid for iterating over the map in C++. If d is unordered map then it can be iterated through the below code

for(auto& [a,b] : d)
{
    count<< "First" << a.first << "Second" << a.second <<endl;
}

To iterate over the vector> matrix as in this case the below code can be used,

vector<vector<int>> mat = { {1,1},{2,2} };
for (auto& a : mat) {
  for (auto& b : a) {
    cout << b << " ";
  }
  cout <<endl;
}


问:
How to remove array if all keys acquired by another array in multidimensional array PHP
can you please help me out in this.
What will be the function to remove 4th and 5th array in PHP.

```<code>Array
(
    [0] => Array
        (
            [10] => 98
            [11] => 1
            [433438] => 8
        )

    [1] => Array
        (
            [10] => 98
            [11] => 1
            [433438] => 1
        )

    [2] => Array
        (
            [13] => 98
            [11] => 2
            [433438] => 8
        )

    [3] => Array
        (
            [14] => 98
            [11] => 2
            [433438] => 1
        )

    [4] => Array
        (
            [10] => 18
            [11] => 1
        )

    [5] => Array
        (
            [14] => 18
            [11] => 2
        )

)
</code>```

Thanks in Advance.

答:
You can use array_pop() function which eliminates the last element of the array but if you use it two times you will get the desired result as

```<code><?php
$data  = [
    1 => [1,2],
    2 => [1,3],
    3 => [1,4]
];
$value = array_pop($data);
$value = array_pop($data);
?>
</code>```

Output

```<code>Array
(
    [1] => Array
        (
            [0] => 1
            [1] => 2
        )

)
</code>```

Body:
can you please help me out in this.
What will be the function to remove 4th and 5th array in PHP.

Array
(
    [0] => Array
        (
            [10] => 98
            [11] => 1
            [433438] => 8
        )

    [1] => Array
        (
            [10] => 98
            [11] => 1
            [433438] => 1
        )

    [2] => Array
        (
            [13] => 98
            [11] => 2
            [433438] => 8
        )

    [3] => Array
        (
            [14] => 98
            [11] => 2
            [433438] => 1
        )

    [4] => Array
        (
            [10] => 18
            [11] => 1
        )

    [5] => Array
        (
            [14] => 18
            [11] => 2
        )

)

Thanks in Advance.

Body:
You can use array_pop() function which eliminates the last element of the array but if you use it two times you will get the desired result as

<?php
$data  = [
    1 => [1,2],
    2 => [1,3],
    3 => [1,4]
];
$value = array_pop($data);
$value = array_pop($data);
?>

Output

Array
(
    [1] => Array
        (
            [0] => 1
            [1] => 2
        )

)


问:
SQL Count Totals Within Date Ranges
I have a CHANGES table with fields VALUE(integer) and CREATED_AT(timestamp). I want to know the total of the VALUE column grouped by each of the past 30 days (without making 30 queries).

So if yesterday there were records created with VALUEs of 10, -7, and 12; I would want a record returned with CREATED_AT = yesterday and TOTAL = 15.

Any help?

答:
```<code>SELECT date(created_at) as CREATED_AT, sum(value) as TOTAL
FROM changes
WHERE created_at >= curdate() - interval 30 day
GROUP BY date(created_at);
</code>```

Title: SQL Count Totals Within Date Ranges


问:
How to write sentence in notepad using keyboard python package
I want to write the output in a separate notepad or ms word using python package keyboard.

```<code>  import keyboard
  keyboard.write('The quick brown fox jumps over the lazy dog.')
</code>```

but it writes these sentence in the command prompt, where I run the script, not in notepad.
How can I make it to control the other software?

答:
You can use pywinauto package which is more efficient and friendly:

from pywinauto.application import Application
app = Application(backend="uia").start('notepad.exe')

# describe the window inside Notepad.exe process
window = app.UntitledNotepad # or app['Untitled - Notepad'], its the same
# wait till the window is really open
window_ready = window.wait('visible')

# Write in some text
app.UntitledNotepad.Edit.type_keys("Hello world", with_spaces = True)
```

NOTE: Some lines are adapted from the documentation

Body:
I want to write the output in a separate notepad or ms word using python package keyboard.

  import keyboard
  keyboard.write('The quick brown fox jumps over the lazy dog.')

but it writes these sentence in the command prompt, where I run the script, not in notepad.
How can I make it to control the other software?

Body:
You can use pywinauto package which is more efficient and friendly:

from pywinauto.application import Application
app = Application(backend="uia").start('notepad.exe')

# describe the window inside Notepad.exe process
window = app.UntitledNotepad # or app['Untitled - Notepad'], its the same
# wait till the window is really open
window_ready = window.wait('visible')

# Write in some text
app.UntitledNotepad.Edit.type_keys("Hello world", with_spaces = True)

NOTE: Some lines are adapted from the documentation


问:
how to reset element after addEventListener
I have this code for client-side file size check on a file upload form (after which I have server side file size check too):

```

My problem is when I select a file larger than the allowed max size and I get the alert button, after that I cannot select a smaller file (if I do I keep getting the same error alert).
How can I reset the listening event so it recalculates the next time a file is added?

thank you

答:
You can reset your input field by this:

```<code>document.getElementById('file_to_upload').value = "";
</code>```

Hope this will be helpful to you.

Body:
I have this code for client-side file size check on a file upload form (after which I have server side file size check too):

My problem is when I select a file larger than the allowed max size and I get the alert button, after that I cannot select a smaller file (if I do I keep getting the same error alert).
How can I reset the listening event so it recalculates the next time a file is added?

thank you

Body:
You can reset your input field by this:

document.getElementById('file_to_upload').value = "";

Hope this will be helpful to you.