问:
GUI goes blank when i try to define the public void actionPerformed(ActionEvent arg0)
When I try to add some function to get data from jtext field under public void actionPerformed(ActionEvent arg0) My GUI goes blank I have attached the images below I can't figure out what's wrong with it.

```<code>    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.JLabel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;

    public class Register extends JFrame {

        private JPanel contentPane;
        private JTextField textField;
        private JTextField textField_1;
        private JTextField textField_2;
        private JTextField textField_3;
        private JTextField textField_4;
        private JLabel lblNewLabel;

        /**
         * Launch the application.
         */
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        Register frame = new Register();
                        frame.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        /**
         * Create the frame.
         */
        public Register() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setBounds(100, 100, 450, 300);
            contentPane = new JPanel();
            contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
            setContentPane(contentPane);
            contentPane.setLayout(null);

            JLabel lblName = new JLabel("Name");
            lblName.setBounds(56, 56, 56, 16);
            contentPane.add(lblName);

            JLabel lblUsername = new JLabel("Username");
            lblUsername.setBounds(56, 85, 77, 16);
            contentPane.add(lblUsername);

            JLabel lblPassword = new JLabel("Password");
            lblPassword.setBounds(56, 114, 56, 16);
            contentPane.add(lblPassword);

            JLabel lblAge = new JLabel("Age");
            lblAge.setBounds(56, 143, 56, 16);
            contentPane.add(lblAge);

            JLabel lblGender = new JLabel("Gender");
            lblGender.setBounds(56, 172, 56, 16);
            contentPane.add(lblGender);

            textField = new JTextField();
            textField.setBounds(130, 53, 116, 19);
            contentPane.add(textField);
            textField.setColumns(10);

            textField_1 = new JTextField();
            textField_1.setBounds(130, 82, 116, 22);
            contentPane.add(textField_1);
            textField_1.setColumns(10);

            textField_2 = new JTextField();
            textField_2.setBounds(130, 111, 116, 22);
            contentPane.add(textField_2);
            textField_2.setColumns(10);

            textField_3 = new JTextField();
            textField_3.setBounds(130, 140, 116, 22);
            contentPane.add(textField_3);
            textField_3.setColumns(10);

            textField_4 = new JTextField();
            textField_4.setBounds(130, 169, 116, 22);
            contentPane.add(textField_4);
            textField_4.setColumns(10);

            JButton btnSubmit = new JButton("Submit");
            btnSubmit.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {

                }
            });
            btnSubmit.setBounds(169, 215, 97, 25);
            contentPane.add(btnSubmit);

            lblNewLabel = new JLabel("New label");
            lblNewLabel.setBounds(330, 56, 56, 16);
            contentPane.add(lblNewLabel);
        }

    }
</code>```

EDIT 1: Added String name to action just to get name.

```<code>JButton btnSubmit = new JButton("Submit");
        btnSubmit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {

                String Name;

            }
        });
</code>```

and This happened

GUI went blank:

答:
You're using an absolute layout. Since you can't pack() the window, you need to at least validate() its contents.

```<code>Register frame = new Register();
frame.validate();
frame.setVisible(true);
</code>```

Now you can see the real problem: you picked bounds for lblPassword and lblNewLabel that cut off the text on my computer. You really need to use a layout, maybe like this.

Body:
When I try to add some function to get data from jtext field under public void actionPerformed(ActionEvent arg0) My GUI goes blank I have attached the images below I can't figure out what's wrong with it.

    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.JLabel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;

    public class Register extends JFrame {

        private JPanel contentPane;
        private JTextField textField;
        private JTextField textField_1;
        private JTextField textField_2;
        private JTextField textField_3;
        private JTextField textField_4;
        private JLabel lblNewLabel;

        /**
         * Launch the application.
         */
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        Register frame = new Register();
                        frame.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        /**
         * Create the frame.
         */
        public Register() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setBounds(100, 100, 450, 300);
            contentPane = new JPanel();
            contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
            setContentPane(contentPane);
            contentPane.setLayout(null);

            JLabel lblName = new JLabel("Name");
            lblName.setBounds(56, 56, 56, 16);
            contentPane.add(lblName);

            JLabel lblUsername = new JLabel("Username");
            lblUsername.setBounds(56, 85, 77, 16);
            contentPane.add(lblUsername);

            JLabel lblPassword = new JLabel("Password");
            lblPassword.setBounds(56, 114, 56, 16);
            contentPane.add(lblPassword);

            JLabel lblAge = new JLabel("Age");
            lblAge.setBounds(56, 143, 56, 16);
            contentPane.add(lblAge);

            JLabel lblGender = new JLabel("Gender");
            lblGender.setBounds(56, 172, 56, 16);
            contentPane.add(lblGender);

            textField = new JTextField();
            textField.setBounds(130, 53, 116, 19);
            contentPane.add(textField);
            textField.setColumns(10);

            textField_1 = new JTextField();
            textField_1.setBounds(130, 82, 116, 22);
            contentPane.add(textField_1);
            textField_1.setColumns(10);

            textField_2 = new JTextField();
            textField_2.setBounds(130, 111, 116, 22);
            contentPane.add(textField_2);
            textField_2.setColumns(10);

            textField_3 = new JTextField();
            textField_3.setBounds(130, 140, 116, 22);
            contentPane.add(textField_3);
            textField_3.setColumns(10);

            textField_4 = new JTextField();
            textField_4.setBounds(130, 169, 116, 22);
            contentPane.add(textField_4);
            textField_4.setColumns(10);

            JButton btnSubmit = new JButton("Submit");
            btnSubmit.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {

                }
            });
            btnSubmit.setBounds(169, 215, 97, 25);
            contentPane.add(btnSubmit);

            lblNewLabel = new JLabel("New label");
            lblNewLabel.setBounds(330, 56, 56, 16);
            contentPane.add(lblNewLabel);
        }

    }

EDIT 1: Added String name to action just to get name.

JButton btnSubmit = new JButton("Submit");
        btnSubmit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent arg0) {

                String Name;

            }
        });

and This happened

GUI went blank:

Body:
You're using an absolute layout. Since you can't pack() the window, you need to at least validate() its contents.

Register frame = new Register();
frame.validate();
frame.setVisible(true);

Now you can see the real problem: you picked bounds for lblPassword and lblNewLabel that cut off the text on my computer. You really need to use a layout, maybe like this.


来源: stackexchange

问:
Installing PyGraphics-1.5.win32.exe
When I try to install PyGraphics-1.5.win32.exe it pops up with an error stating:

"The program can't start because MSVCR71.dll is missing from your computer. Try reinstalling the program to fix this problem."

I have tried reinstalling Python and have had no luck. My installation currently includes PyWin, Pyserial, and PIL on Windows 7 x64.

Any help much appreciated, thank you.

答:
You could Google for the missing DLL, and copy it into the Python installation directory.
But it's probably easier to just grab the Visual Studio 2005 SP1 Redistributable (x86) runtime package from Microsoft. I think you'll need the x86 version of the runtime (rather than x64), since PyGraphics-win32 sounds like a 32-bit library, not 64-bit.</p>

ContentLicense: CC BY-SA 2.5

Title: Installing PyGraphics-1.5.win32.exe


问:
Removing the [''] format from a file
I have to rip my cd library in Flac to archive them and long story short the filename when ripped doesn't include the track number, which is throwing off the playlist order when played on my audio player.

To save the trouble to rename them manually I wrote this morning a little script:

```<code>import os
from mutagen.flac import FLAC

chemin= r'E:\CD\CdName'

for titre in os.listdir(chemin):
    track= FLAC(os.path.join(chemin, titre))
    tracknumber = track.tags["tracknumber"]
    tracktitle= track.tags["title"]
    newtitle= str(tracknumber) + " " + str(tracktitle)
    os.rename(os.path.join(chemin,titre),os.path.join(chemin,str(newtitle)))
</code>```

Sorry it's not the cleanest code, I am still a newbie in python.

It works fine for its purpose except that it has the format ['text'] in the track title which results in something like this ['01']  ['TrackName'] for the filename which is not convenient.

As a consequence I was wondering if there was a possibility to remove this unwanted formating in the track name.

答:
As the problem is resolved thanks to you all, I thought it may interest people in the same case to have this script:

```<code>import os
from mutagen.flac import FLAC

chemin= r'C:\XXXXX' #your path here

for titre in os.listdir(chemin):
    track= FLAC(os.path.join(chemin, titre))
    tracknumber = track.tags["tracknumber"]
    tracktitle= track.tags["title"]
    newtitle= " - ".join([tracknumber.pop(),tracktitle.pop()])+".flac"
    newtitle = newtitle.replace("?","")
    os.rename(os.path.join(chemin,titre),os.path.join(chemin,str(newtitle)))
</code>```

ps: I made a small edit to remove the problem with the question mark which is not compatible with file format

ContentLicense: CC BY-SA 3.0

Title: Removing the [''] format from a file

Body:
I have to rip my cd library in Flac to archive them and long story short the filename when ripped doesn't include the track number, which is throwing off the playlist order when played on my audio player.

To save the trouble to rename them manually I wrote this morning a little script:

import os
from mutagen.flac import FLAC

chemin= r'E:\CD\CdName'

for titre in os.listdir(chemin):
    track= FLAC(os.path.join(chemin, titre))
    tracknumber = track.tags["tracknumber"]
    tracktitle= track.tags["title"]
    newtitle= str(tracknumber) + " " + str(tracktitle)
    os.rename(os.path.join(chemin,titre),os.path.join(chemin,str(newtitle)))

Sorry it's not the cleanest code, I am still a newbie in python.

It works fine for its purpose except that it has the format ['text'] in the track title which results in something like this ['01']  ['TrackName'] for the filename which is not convenient.

As a consequence I was wondering if there was a possibility to remove this unwanted formating in the track name.

Body:
As the problem is resolved thanks to you all, I thought it may interest people in the same case to have this script:

import os
from mutagen.flac import FLAC

chemin= r'C:\XXXXX' #your path here

for titre in os.listdir(chemin):
    track= FLAC(os.path.join(chemin, titre))
    tracknumber = track.tags["tracknumber"]
    tracktitle= track.tags["title"]
    newtitle= " - ".join([tracknumber.pop(),tracktitle.pop()])+".flac"
    newtitle = newtitle.replace("?","")
    os.rename(os.path.join(chemin,titre),os.path.join(chemin,str(newtitle)))

ps: I made a small edit to remove the problem with the question mark which is not compatible with file format


问:
How to not show all labels on ggplot axis?
I'm trying to using ggplot2 to plot this: But as you can see on the x axis you can't read anything...

So how can I show on the x axis the value every 10 years, for example?

This is my command:

ggplot(prova, aes(x=year, y=mass..g.)) + geom_line(aes(group = 1))

答:
The other answers have covered the case where your dates are numerical years, but if (as @Gregor notes) your dates are actual Date objects, it's a lot easier:

```<code>scale_x_date(name = 'My date axis title', date_breaks = '20 years',
        date_labels = '%Y')
</code>```

With scale_date, you can control the breaks with intuitive language and the labelling with (hopefully) familiar strptime notation.

Body:
The other answers have covered the case where your dates are numerical years, but if (as @Gregor notes) your dates are actual Date objects, it's a lot easier:

scale_x_date(name = 'My date axis title', date_breaks = '20 years',
        date_labels = '%Y')

With scale_date, you can control the breaks with intuitive language and the labelling with (hopefully) familiar strptime notation.


问:
C Multidimensional Array: Am I missing something?
I'm currently learning C, and I have just written a draft of a program that allows a user to move a player around a character-based maze/path. I have built the maze/path as multidimensional character array, with a while loop controlling the player's position by replacing certain characters in the array. Here is the multidimensional array I have initialised:

```<code>char maze[5][7] = {
    {"_", "_", "_", "_", "_"},
    {"|", " ", " ", " ", "|"},
    {"|", " ", "|", " ", "|"},
    {"|", " ", "|", "_", "|"},
    {"|", "_", " ", " ", "|"},
    {"|", " ", "|", " ", "|"},
    {"|", "_", "_", "_", "|"}
};
</code>```

However, when I try to compile, I get this error:

```<code>error: '}' expected
</code>```

The first row in the array is apparently missing some sort of closing bracket, although I have checked proper array syntax multiple times and this appears to be correct. What am I missing? Are there any other issues with this?

Body:
I'm currently learning C, and I have just written a draft of a program that allows a user to move a player around a character-based maze/path. I have built the maze/path as multidimensional character array, with a while loop controlling the player's position by replacing certain characters in the array. Here is the multidimensional array I have initialised:

char maze[5][7] = {
    {"_", "_", "_", "_", "_"},
    {"|", " ", " ", " ", "|"},
    {"|", " ", "|", " ", "|"},
    {"|", " ", "|", "_", "|"},
    {"|", "_", " ", " ", "|"},
    {"|", " ", "|", " ", "|"},
    {"|", "_", "_", "_", "|"}
};

However, when I try to compile, I get this error:

error: '}' expected

The first row in the array is apparently missing some sort of closing bracket, although I have checked proper array syntax multiple times and this appears to be correct. What am I missing? Are there any other issues with this?

Body:
You need to replace " with ' because a char is a single sign.
The second problem is, that you assign the length wrong.

Replace the first with the second length.

char maze[7][5] = {
    {'_', '_', '_', '_', '_'},
    {'|', ' ', ' ', ' ', '|'},
    {'|', ' ', '|', ' ', '|'},
    {'|', ' ', '|', '_', '|'},
    {'|', '_', ' ', ' ', '|'},
    {'|', ' ', '|', ' ', '|'},
    {'|', '_', '_', '_', '|'}
};


问:
space indentation expected - Codacy
I heard that good practice is to use something to check my code. I found something called Codacy. I understand everything except 'space indentation expected' from TSLint and TSLint4. Is it because my ident in project is tab? If yes, how can I change this one rule in codacy?

```<code>import {NgModule} from '@angular/core';
import {CommonModule}  from '@angular/common';
import {RouterModule, Routes} from '@angular/router';

import {TranslationModule} from '../translate.module';

const adminRoutes: Routes = [
    {
        path: 'admin',
        children: [
        ]
    }
];

@NgModule({
    imports: [
    CommonModule, RouterModule.forRoot(adminRoutes), TranslationModule
    ],
    declarations: [
    ],
    exports: [
    ]
})
export class AdminModule { }
</code>```

Codacy show problem with

```<code>{
    path: 'admin',
    children: [
    ]
}
</code>```

答:
Have a look at the documentation. for instance:</p>

```<code>"indent": [true, "tabs", 2]
</code>```

Title: space indentation expected - Codacy

Body:
I heard that good practice is to use something to check my code. I found something called Codacy. I understand everything except 'space indentation expected' from TSLint and TSLint4. Is it because my ident in project is tab? If yes, how can I change this one rule in codacy?

import {NgModule} from '@angular/core';
import {CommonModule}  from '@angular/common';
import {RouterModule, Routes} from '@angular/router';

import {TranslationModule} from '../translate.module';

const adminRoutes: Routes = [
    {
        path: 'admin',
        children: [
        ]
    }
];

@NgModule({
    imports: [
    CommonModule, RouterModule.forRoot(adminRoutes), TranslationModule
    ],
    declarations: [
    ],
    exports: [
    ]
})
export class AdminModule { }

Codacy show problem with

{
    path: 'admin',
    children: [
    ]
}

Body:
Have a look at the documentation. for instance:

"indent": [true, "tabs", 2]


问:
SELECT query with NO LOCK
I want to use SELECT WITH NOLOCK, the table on which i want to use SELECT WITH NOLOCK query have no updation query and the data i want to fetch are less the current inserted record.I want to use NOLOCK because sometime i am getting Timeout exception in SELECT query. I think this is because of Table would be LOCKED by Insert query which is running constantly and SELECT query have to wait for long time so it's giving Timeout error.

So please suggest should i use NOLOCK here, I have read some post were written about uncommitted transaction and they suggest not to use NOLOCK.

答: Not only you can "see results that are not yet committed " but you can read some rows twice or not read them at all. So we cannot advice you nothing without knowing your table structure and your query. If you are blocked even when reading "data less the current inserted record" may be you just have no appropriate index on your table?</p>

Title: SELECT query with NO LOCK


问:
button doesn't click in android studio
```<code>private Button mfactbutton;
private TextView mfacttext;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_fun_fact);

    Button mfactbutton = (Button) findViewById(R.id.button);
    TextView mfacttext = (TextView) findViewById(R.id.textView2);

    // now we need to make out button to click
    View.OnClickListener Listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String[] facts = {
                    "Ants stretch when they wake up in the morning.",
                    "Ostriches can run faster than horses.",
                    "Olympic gold medals are actually made mostly of silver.",
                    "You are born with 300 bones; by the time you are an adult you will have 206.",
                    "It takes about 8 minutes for light from the Sun to reach Earth.",
                    "Some bamboo plants can grow almost a meter in just one day.",
                    "The state of Florida is bigger than England.",
                    "Some penguins can leap 2-3 meters out of the water.",
                    "On average, it takes 66 days to form a new habit.",
                    "Mammoths still walked the earth when the Great Pyramid was being built." };

            String fact = "";

            // randomly select a fact

            Random randomGenerator = new Random();
            int randomNumber = randomGenerator.nextInt(facts.length);
            fact = facts[randomNumber] + "";
        }
    };
    mfactbutton.setOnClickListener(Listener);

}
</code>```

}

Hey everyone! i need help! my button doesn't just simply clicl!!!!! heeeeeeeeelp!i'm just trying to make a simple button that changes the textview2 with each click! at first it was working but now it started not to work.

答:
Your Button clicked properly but the main thing is you did not set fact value to TextView.

#. As you have declared Button and TextView outside onCreate(), no need to declare it again inside onCreate().

Use:

```<code>    mfactbutton = (Button) findViewById(R.id.button);
    mfacttext = (TextView) findViewById(R.id.textView2);
</code>```

Instead of:

```<code>    Button mfactbutton = (Button) findViewById(R.id.button);
    TextView mfacttext = (TextView) findViewById(R.id.textView2);
</code>```

#. In onClick() method show fact value on TextView or show Toast message:

```<code>    // TextView
    mfacttext.setText(fact);

    // Toast
    Toast.makeText(getApplicationContext(), "Fact: " + fact, Toast.LENGTH_SHORT).show();
</code>```

Here is the working code:

```<code>public class MainActivity extends AppCompatActivity {

    private Button mfactbutton;
    private TextView mfacttext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mfactbutton = (Button) findViewById(R.id.button);
        mfacttext = (TextView) findViewById(R.id.textView2);

        // now we need to make out button to click
        View.OnClickListener Listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String[] facts = {
                        "Ants stretch when they wake up in the morning.",
                        "Ostriches can run faster than horses.",
                        "Olympic gold medals are actually made mostly of silver.",
                        "You are born with 300 bones; by the time you are an adult you will have 206.",
                        "It takes about 8 minutes for light from the Sun to reach Earth.",
                        "Some bamboo plants can grow almost a meter in just one day.",
                        "The state of Florida is bigger than England.",
                        "Some penguins can leap 2-3 meters out of the water.",
                        "On average, it takes 66 days to form a new habit.",
                        "Mammoths still walked the earth when the Great Pyramid was being built." };

                String fact = "";

                Random randomGenerator = new Random();
                int randomNumber = randomGenerator.nextInt(facts.length);

                fact = facts[randomNumber] + "";

                mfacttext.setText(fact);
                Toast.makeText(getApplicationContext(), "Fact: " + fact, Toast.LENGTH_SHORT).show();
            }
        };

        mfactbutton.setOnClickListener(Listener);
    }
}
</code>```

OUTPUT:

Title: button doesn't click in android studio

Body:
private Button mfactbutton;
private TextView mfacttext;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_fun_fact);

    Button mfactbutton = (Button) findViewById(R.id.button);
    TextView mfacttext = (TextView) findViewById(R.id.textView2);

    // now we need to make out button to click
    View.OnClickListener Listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String[] facts = {
                    "Ants stretch when they wake up in the morning.",
                    "Ostriches can run faster than horses.",
                    "Olympic gold medals are actually made mostly of silver.",
                    "You are born with 300 bones; by the time you are an adult you will have 206.",
                    "It takes about 8 minutes for light from the Sun to reach Earth.",
                    "Some bamboo plants can grow almost a meter in just one day.",
                    "The state of Florida is bigger than England.",
                    "Some penguins can leap 2-3 meters out of the water.",
                    "On average, it takes 66 days to form a new habit.",
                    "Mammoths still walked the earth when the Great Pyramid was being built." };

            String fact = "";

            // randomly select a fact

            Random randomGenerator = new Random();
            int randomNumber = randomGenerator.nextInt(facts.length);
            fact = facts[randomNumber] + "";
        }
    };
    mfactbutton.setOnClickListener(Listener);

}

}

Hey everyone! i need help! my button doesn't just simply clicl!!!!! heeeeeeeeelp!i'm just trying to make a simple button that changes the textview2 with each click! at first it was working but now it started not to work.

Body:
Your Button clicked properly but the main thing is you did not set fact value to TextView.

#. As you have declared Button and TextView outside onCreate(), no need to declare it again inside onCreate().

Use:

    mfactbutton = (Button) findViewById(R.id.button);
    mfacttext = (TextView) findViewById(R.id.textView2);

Instead of:

    Button mfactbutton = (Button) findViewById(R.id.button);
    TextView mfacttext = (TextView) findViewById(R.id.textView2);

#. In onClick() method show fact value on TextView or show Toast message:

    // TextView
    mfacttext.setText(fact);

    // Toast
    Toast.makeText(getApplicationContext(), "Fact: " + fact, Toast.LENGTH_SHORT).show();

Here is the working code:

public class MainActivity extends AppCompatActivity {

    private Button mfactbutton;
    private TextView mfacttext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mfactbutton = (Button) findViewById(R.id.button);
        mfacttext = (TextView) findViewById(R.id.textView2);

        // now we need to make out button to click
        View.OnClickListener Listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String[] facts = {
                        "Ants stretch when they wake up in the morning.",
                        "Ostriches can run faster than horses.",
                        "Olympic gold medals are actually made mostly of silver.",
                        "You are born with 300 bones; by the time you are an adult you will have 206.",
                        "It takes about 8 minutes for light from the Sun to reach Earth.",
                        "Some bamboo plants can grow almost a meter in just one day.",
                        "The state of Florida is bigger than England.",
                        "Some penguins can leap 2-3 meters out of the water.",
                        "On average, it takes 66 days to form a new habit.",
                        "Mammoths still walked the earth when the Great Pyramid was being built." };

                String fact = "";

                Random randomGenerator = new Random();
                int randomNumber = randomGenerator.nextInt(facts.length);

                fact = facts[randomNumber] + "";

                mfacttext.setText(fact);
                Toast.makeText(getApplicationContext(), "Fact: " + fact, Toast.LENGTH_SHORT).show();
            }
        };

        mfactbutton.setOnClickListener(Listener);
    }
}

OUTPUT:


问:
Jenkins Android Emulator Plugin not starting, Timeout after 90000 milliseconds, adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
I am trying to run android tests on my Jenkins server.
The fist problem is that my machine does not support hardware acceleration. I can see this in the logs so it could be the problem:

```<code>15:56:33 emulator: CPU Acceleration status: KVM requires a CPU that supports vmx or svm
15:56:33 emulator: WARNING: x86_64 emulation may not work without hardware acceleration!
</code>```

I can start the emulator by passing the following flags:

```<code>-accel off  -no-accel   -no-audio -gpu off -verbose
</code>```

But it seems to wait for the emulator and times out.
Please see the full logs from the Jenkins server:

```<code>15:55:34 Started by user Paul Stafford
15:55:34 Building in workspace /var/lib/jenkins/workspace/AndroidJenkins
15:55:34  > git rev-parse --is-inside-work-tree # timeout=10
15:55:34 Fetching changes from the remote Git repository
15:55:34  > git config remote.origin.url https://www.boomtastic.org/boomtastic/mobile-android-boom.git # timeout=10
15:55:34 Fetching upstream changes from https://www.boomtastic.org/boomtastic/mobile-android-boom.git
15:55:34  > git --version # timeout=10
15:55:34 using GIT_ASKPASS to set credentials
15:55:34  > git fetch --tags --progress https://www.boomtastic.org/boomtastic/mobile-android-boom.git +refs/heads/*:refs/remotes/origin/*
15:55:37  > git rev-parse refs/remotes/origin/feature-bees/new_android_app^{commit} # timeout=10
15:55:37  > git rev-parse refs/remotes/origin/origin/feature-bees/new_android_app^{commit} # timeout=10
15:55:37 Checking out Revision b3f9bf59d5a55b33a4eb12914ff4a6c3eb5ea7f6 (refs/remotes/origin/feature-bees/new_android_app)
15:55:37  > git config core.sparsecheckout # timeout=10
15:55:37  > git checkout -f b3f9bf59d5a55b33a4eb12914ff4a6c3eb5ea7f6
15:55:37  > git rev-list b3f9bf59d5a55b33a4eb12914ff4a6c3eb5ea7f6 # timeout=10
15:55:37 [android] Using Android SDK: /opt/android-sdk-linux25.2.5
15:55:37 [android] Creating Android AVD: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd
15:55:37 [android] /opt/android-sdk-linux25.2.5/tools/android create avd -f -a -c 32M -s WVGA800 -n hudson_en-US_160_WVGA_android-23_x86_64_-jenkins -t android-23 --abi x86_64
15:55:50 $ /opt/android-sdk-linux25.2.5/platform-tools/adb start-server
15:55:53 * daemon not running. starting it now at tcp:5825 *
15:55:53 * daemon started successfully *
15:55:53 $ /opt/android-sdk-linux25.2.5/platform-tools/adb start-server
15:55:53 [android] Starting Android emulator
15:55:53 $ /opt/android-sdk-linux25.2.5/tools/emulator -engine classic -ports 5758,5759 -report-console tcp:5863,max=60 -prop persist.sys.language=en -prop persist.sys.country=US -avd hudson_en-US_160_WVGA_android-23_x86_64_-jenkins -no-snapshot-load -no-snapshot-save -wipe-data -no-window -accel off -no-accel -no-audio -gpu off -verbose
15:55:53 WARNING: Force to use classic engine to support snapshot.
15:55:54 emulator: Android virtual device file at: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.ini
15:55:54 emulator: virtual device content at /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd
15:55:54 emulator: virtual device config file: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/config.ini
15:55:54 emulator: using core hw config path: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/hardware-qemu.ini
15:55:54 emulator: Found AVD target API level: 23
15:55:54 emulator: Read property file at /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//build.prop
15:55:54 emulator: No boot.prop property file found.
15:55:54 emulator: found skin 'WVGA800' in directory: /opt/android-sdk-linux25.2.5/platforms/android-23/skins/
15:55:54 emulator: autoconfig: -skin WVGA800
15:55:54 emulator: autoconfig: -skindir /opt/android-sdk-linux25.2.5/platforms/android-23/skins/
15:55:54 emulator: found skin-specific hardware.ini: /opt/android-sdk-linux25.2.5/platforms/android-23/skins//WVGA800/hardware.ini
15:55:54 emulator: autoconfig: -kernel /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//kernel-qemu
15:55:54 emulator: Target arch = 'x86_64'
15:55:54 emulator: Auto-detect: Kernel image requires new device naming scheme.
15:55:54 emulator: Auto-detect: Kernel does not support YAFFS2 partitions.
15:55:54 emulator: autoconfig: -ramdisk /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//ramdisk.img
15:55:54 emulator: Using initial system image: /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//system.img
15:55:54 emulator: autoconfig: -initdata /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/userdata.img
15:55:54 emulator: autoconfig: -cache /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/cache.img
15:55:54 emulator: autoconfig: -sdcard /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/sdcard.img
15:55:54 emulator: Increasing RAM size to 1024MB
15:55:54 emulator: VM heap size 48MB is below hardware specified minimum of 192MB,setting it to that value
15:55:54 emulator: System image is read only
15:55:54 emulator: autoconfig: -snapstorage /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/snapshots.img
15:55:54 emulator: GPU emulation is disabled
15:55:54 emulator: Found 2 DNS servers: 10.1.10.3 10.1.10.5
15:55:54 emulator: trying to load skin file '/opt/android-sdk-linux25.2.5/platforms/android-23/skins//WVGA800/layout'
15:55:54 emulator: Found 2 DNS servers: 10.1.10.3 10.1.10.5
15:55:54 emulator: WARNING: Classic qemu does not support SMP. The hw.cpu.ncore option from your config file is ignored.
15:55:54 Content of hardware configuration file:
15:55:54   hw.cpu.arch = x86_64
15:55:54   hw.cpu.ncore = 2
15:55:54   hw.ramSize = 1024
15:55:54   hw.screen = multi-touch
15:55:54   hw.mainKeys = true
15:55:54   hw.trackBall = true
15:55:54   hw.keyboard = false
15:55:54   hw.keyboard.lid = false
15:55:54   hw.keyboard.charmap = qwerty2
15:55:54   hw.dPad = true
15:55:54   hw.gsmModem = true
15:55:54   hw.gps = true
15:55:54   hw.battery = true
15:55:54   hw.accelerometer = true
15:55:54   hw.audioInput = true
15:55:54   hw.audioOutput = true
15:55:54   hw.sdCard = true
15:55:54   hw.sdCard.path = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/sdcard.img
15:55:54   disk.cachePartition = true
15:55:54   disk.cachePartition.path = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/cache.img
15:55:54   disk.cachePartition.size = 66m
15:55:54   hw.lcd.width = 480
15:55:54   hw.lcd.height = 800
15:55:54   hw.lcd.depth = 16
15:55:54   hw.lcd.density = 160
15:55:54   hw.lcd.backlight = true
15:55:54   hw.gpu.enabled = false
15:55:54   hw.gpu.mode = off
15:55:54   hw.gpu.blacklisted = no
15:55:54   hw.initialOrientation = portrait
15:55:54   hw.camera.back = emulated
15:55:54   hw.camera.front = none
15:55:54   vm.heapSize = 192
15:55:54   hw.sensors.light = true
15:55:54   hw.sensors.pressure = true
15:55:54   hw.sensors.humidity = true
15:55:54   hw.sensors.proximity = true
15:55:54   hw.sensors.magnetic_field = true
15:55:54   hw.sensors.orientation = true
15:55:54   hw.sensors.temperature = true
15:55:54   hw.useext4 = true
15:55:54   kernel.path = /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//kernel-qemu
15:55:54   kernel.newDeviceNaming = yes
15:55:54   kernel.supportsYaffs2 = no
15:55:54   disk.ramdisk.path = /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//ramdisk.img
15:56:33   disk.systemPartition.initPath = /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//system.img
15:56:33   disk.systemPartition.size = 1280m
15:56:33   disk.dataPartition.path = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/userdata-qemu.img
15:56:33   disk.dataPartition.initPath = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/userdata.img
15:56:33   disk.dataPartition.size = 2g
15:56:33   disk.snapStorage.path = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/snapshots.img
15:56:33   avd.name = hudson_en-US_160_WVGA_android-23_x86_64_-jenkins
15:56:33 .
15:56:33 emulator: CPU Acceleration: DISABLED
15:56:33 emulator: CPU Acceleration status: KVM requires a CPU that supports vmx or svm
15:56:33 emulator: WARNING: x86_64 emulation may not work without hardware acceleration!
15:56:33 QEMU options list:
15:56:33 emulator: argv[00] = "/opt/android-sdk-linux25.2.5/tools/emulator64-x86"
15:56:33 emulator: argv[01] = "-audio"
15:56:33 emulator: argv[02] = "none"
15:56:33 emulator: argv[03] = "-dns-server"
15:56:33 emulator: argv[04] = "10.1.10.3,10.1.10.5"
15:56:33 emulator: argv[05] = "-serial"
15:56:33 emulator: argv[06] = "null"
15:56:33 emulator: argv[07] = "-serial"
15:56:33 emulator: argv[08] = "null"
15:56:33 emulator: argv[09] = "-boot-property"
15:56:33 emulator: argv[10] = "persist.sys.language=en"
15:56:33 emulator: argv[11] = "-boot-property"
15:56:33 emulator: argv[12] = "persist.sys.country=US"
15:56:33 emulator: argv[13] = "-android-ports"
15:56:33 emulator: argv[14] = "5758,5759"
15:56:33 emulator: argv[15] = "-android-report-console"
15:56:33 emulator: argv[16] = "tcp:5863,max=60"
15:56:33 emulator: argv[17] = "-disable-kvm"
15:56:33 emulator: argv[18] = "-android-hw"
15:56:33 emulator: argv[19] = "/var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/hardware-qemu.ini"
15:56:33 emulator: argv[20] = "-append"
15:56:33 emulator: argv[21] = "qemu=1 androidboot.hardware=goldfish clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=0 ndns=2"
15:56:33 Concatenated QEMU options:
15:56:33  /opt/android-sdk-linux25.2.5/tools/emulator64-x86 -audio none -dns-server 10.1.10.3,10.1.10.5 -serial null -serial null -boot-property persist.sys.language=en -boot-property persist.sys.country=US -android-ports 5758,5759 -android-report-console tcp:5863,max=60 -disable-kvm -android-hw /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/hardware-qemu.ini -append 'qemu=1 androidboot.hardware=goldfish clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=0 ndns=2'
15:56:33 emulator: Starting QEMU main loop
15:56:33 emulator: registered 'boot-properties' qemud service
15:56:33 emulator: Using kernel serial device prefix: ttyGF
15:56:33 emulator: AVD Name: hudson_en-US_160_WVGA_android-23_x86_64_-jenkins
15:56:33 emulator: Ramdisk image contains fstab.goldfish file
15:56:33 emulator: Found format of system partition: 'ext4'
15:56:33 emulator: Found format of userdata partition: 'ext4'
15:56:33 emulator: Found format of cache partition: 'ext4'
15:56:33 emulator: system partition format: ext4
15:56:33 emulator: nand_add_dev: system,size=0x50000000,file=/opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//system.img,pagesize=512,extrasize=0,readonly
15:56:33 emulator: userdata partition format: ext4
15:56:33 emulator: nand_add_dev: userdata,size=0x80000000,file=/var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/userdata-qemu.img,pagesize=512,extrasize=0
15:56:33 emulator: cache partition format: ext4
15:56:33 emulator: Creating empty cache partition image at: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/cache.img
15:56:33 Creating filesystem with parameters:
15:56:33     Size: 69206016
15:56:33     Block size: 4096
15:56:33     Blocks per group: 32768
15:56:33     Inodes per group: 4224
15:56:33     Inode size: 256
15:56:33     Journal blocks: 1024
15:56:33     Label:
15:56:33     Blocks: 16896
15:56:33     Block groups: 1
15:56:33     Reserved block group size: 7
15:56:33 Created filesystem with 11/4224 inodes and 1302/16896 blocks
15:56:33 emulator: nand_add_dev: cache,size=0x4200000,file=/var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/cache.img,pagesize=512,extrasize=0
15:56:33 emulator: Adding boot property: 'dalvik.vm.heapsize' = '192m'
15:56:33 emulator: Adding boot property: 'qemu.sf.lcd_density' = '160'
15:56:33 emulator: Adding boot property: 'qemu.hw.mainkeys' = '1'
15:56:33 emulator: Adding boot property: 'qemu.sf.fake_camera' = 'back'
15:56:33 emulator: Found 2 DNS servers: 10.1.10.3 10.1.10.5
15:56:33 emulator: Kernel parameters: qemu=1 androidboot.hardware=goldfish clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=0 ndns=2
15:56:33 emulator:     trying to find: /opt/android-sdk-linux25.2.5/tools/bios.bin
15:56:33
15:56:33 emulator:     trying to find: /opt/android-sdk-linux25.2.5/tools/lib/pc-bios/bios.bin
15:56:33
15:56:33 emulator:     trying to find: /opt/android-sdk-linux25.2.5/tools/vgabios-cirrus.bin
15:56:33
15:56:33 emulator:     trying to find: /opt/android-sdk-linux25.2.5/tools/lib/pc-bios/vgabios-cirrus.bin
15:56:33
15:56:34 emulator: Adding boot property: 'persist.sys.language' = 'en'
15:56:34 emulator: Adding boot property: 'persist.sys.country' = 'US'
15:56:34 emulator: (android_emulation_setup) using custom adb server port 5825
15:56:34 emulator: ro.adb.qemud invalid or not found, API >= 16, defaulting ro.adb.qemud = 0
15:56:34 emulator: (setup_console_and_adb_ports) trying console port 5758, adb port 5759 (legacy: true)
15:56:34 emulator: (android_console_start) initializing on port 5758
15:56:34 emulator: sent '0012host:emulator:5759' to ADB server
15:56:34 emulator: WARNING: Requested adb port (5759) is outside the recommended range [5555,5586]. ADB may not function properly for the emulator. See -help-port for details.
15:56:34 emulator: Listening for console connections on port: 5758
15:56:34 emulator: Serial number of this emulator (for ADB): emulator-5758
15:56:34 emulator: trying to find console-report client on tcp:5863
15:56:34 emulator: console port number sent to remote. resuming boot
15:56:34 [android] Emulator reported that the console is available on port 5,758
15:56:34 [android] Waiting for emulator to finish booting...
15:56:34 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
15:56:34 emulator: android_hw_fingerprint_init: fingerprint qemud listen service initialized
15:56:34
15:56:34 emulator: Skipping metrics reporting: No user opt-in.
15:58:04 ERROR: Timeout after 90000 milliseconds
15:58:04 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
15:59:47 ERROR: Timeout after 90000 milliseconds
15:59:47 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:01:31 ERROR: Timeout after 90000 milliseconds
16:01:31 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:03:14 ERROR: Timeout after 90000 milliseconds
16:03:14 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:04:58 ERROR: Timeout after 90000 milliseconds
16:04:58 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:06:42 ERROR: Timeout after 90000 milliseconds
16:06:42 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:08:25 ERROR: Timeout after 90000 milliseconds
16:08:25 [android] Timed-out after waiting 720 seconds for emulator
16:08:39 [android] Stopping Android emulator
16:08:39 $ /opt/android-sdk-linux25.2.5/platform-tools/adb kill-server
16:08:40 Finished: NOT_BUILT
</code>```

Any idea how to take my investigation forward?

答:
It was already a year ago, but here is what I suggest for everybody who tries to set up Android build process in Jenkins:

Access Jenkins machine/server directly (e.g. via ssh) and try to launch emulator from terminal. In logs posted by OP, you can see that Jenkins tried to launch emulator:

15:56:34 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim

Maybe 90s (90000 miliseconds) isn't enough? You can launch following command on your server from terminal:

```<code>/opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
</code>```

and measure how long it actually take.

If it takes too much time you may consider to keep emulator running on Jenkins machine and just assume it's always ready, so you need run following command to your UI/instrumented tests:

```<code>./gradlew connectedAndroidTest
</code>```

Body:
I am trying to run android tests on my Jenkins server.
The fist problem is that my machine does not support hardware acceleration. I can see this in the logs so it could be the problem:

15:56:33 emulator: CPU Acceleration status: KVM requires a CPU that supports vmx or svm
15:56:33 emulator: WARNING: x86_64 emulation may not work without hardware acceleration!

I can start the emulator by passing the following flags:

-accel off  -no-accel   -no-audio -gpu off -verbose

But it seems to wait for the emulator and times out.
Please see the full logs from the Jenkins server:

15:55:34 Started by user Paul Stafford
15:55:34 Building in workspace /var/lib/jenkins/workspace/AndroidJenkins
15:55:34  > git rev-parse --is-inside-work-tree # timeout=10
15:55:34 Fetching changes from the remote Git repository
15:55:34  > git config remote.origin.url https://www.boomtastic.org/boomtastic/mobile-android-boom.git # timeout=10
15:55:34 Fetching upstream changes from https://www.boomtastic.org/boomtastic/mobile-android-boom.git
15:55:34  > git --version # timeout=10
15:55:34 using GIT_ASKPASS to set credentials
15:55:34  > git fetch --tags --progress https://www.boomtastic.org/boomtastic/mobile-android-boom.git +refs/heads/*:refs/remotes/origin/*
15:55:37  > git rev-parse refs/remotes/origin/feature-bees/new_android_app^{commit} # timeout=10
15:55:37  > git rev-parse refs/remotes/origin/origin/feature-bees/new_android_app^{commit} # timeout=10
15:55:37 Checking out Revision b3f9bf59d5a55b33a4eb12914ff4a6c3eb5ea7f6 (refs/remotes/origin/feature-bees/new_android_app)
15:55:37  > git config core.sparsecheckout # timeout=10
15:55:37  > git checkout -f b3f9bf59d5a55b33a4eb12914ff4a6c3eb5ea7f6
15:55:37  > git rev-list b3f9bf59d5a55b33a4eb12914ff4a6c3eb5ea7f6 # timeout=10
15:55:37 [android] Using Android SDK: /opt/android-sdk-linux25.2.5
15:55:37 [android] Creating Android AVD: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd
15:55:37 [android] /opt/android-sdk-linux25.2.5/tools/android create avd -f -a -c 32M -s WVGA800 -n hudson_en-US_160_WVGA_android-23_x86_64_-jenkins -t android-23 --abi x86_64
15:55:50 $ /opt/android-sdk-linux25.2.5/platform-tools/adb start-server
15:55:53 * daemon not running. starting it now at tcp:5825 *
15:55:53 * daemon started successfully *
15:55:53 $ /opt/android-sdk-linux25.2.5/platform-tools/adb start-server
15:55:53 [android] Starting Android emulator
15:55:53 $ /opt/android-sdk-linux25.2.5/tools/emulator -engine classic -ports 5758,5759 -report-console tcp:5863,max=60 -prop persist.sys.language=en -prop persist.sys.country=US -avd hudson_en-US_160_WVGA_android-23_x86_64_-jenkins -no-snapshot-load -no-snapshot-save -wipe-data -no-window -accel off -no-accel -no-audio -gpu off -verbose
15:55:53 WARNING: Force to use classic engine to support snapshot.
15:55:54 emulator: Android virtual device file at: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.ini
15:55:54 emulator: virtual device content at /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd
15:55:54 emulator: virtual device config file: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/config.ini
15:55:54 emulator: using core hw config path: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/hardware-qemu.ini
15:55:54 emulator: Found AVD target API level: 23
15:55:54 emulator: Read property file at /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//build.prop
15:55:54 emulator: No boot.prop property file found.
15:55:54 emulator: found skin 'WVGA800' in directory: /opt/android-sdk-linux25.2.5/platforms/android-23/skins/
15:55:54 emulator: autoconfig: -skin WVGA800
15:55:54 emulator: autoconfig: -skindir /opt/android-sdk-linux25.2.5/platforms/android-23/skins/
15:55:54 emulator: found skin-specific hardware.ini: /opt/android-sdk-linux25.2.5/platforms/android-23/skins//WVGA800/hardware.ini
15:55:54 emulator: autoconfig: -kernel /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//kernel-qemu
15:55:54 emulator: Target arch = 'x86_64'
15:55:54 emulator: Auto-detect: Kernel image requires new device naming scheme.
15:55:54 emulator: Auto-detect: Kernel does not support YAFFS2 partitions.
15:55:54 emulator: autoconfig: -ramdisk /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//ramdisk.img
15:55:54 emulator: Using initial system image: /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//system.img
15:55:54 emulator: autoconfig: -initdata /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/userdata.img
15:55:54 emulator: autoconfig: -cache /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/cache.img
15:55:54 emulator: autoconfig: -sdcard /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/sdcard.img
15:55:54 emulator: Increasing RAM size to 1024MB
15:55:54 emulator: VM heap size 48MB is below hardware specified minimum of 192MB,setting it to that value
15:55:54 emulator: System image is read only
15:55:54 emulator: autoconfig: -snapstorage /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/snapshots.img
15:55:54 emulator: GPU emulation is disabled
15:55:54 emulator: Found 2 DNS servers: 10.1.10.3 10.1.10.5
15:55:54 emulator: trying to load skin file '/opt/android-sdk-linux25.2.5/platforms/android-23/skins//WVGA800/layout'
15:55:54 emulator: Found 2 DNS servers: 10.1.10.3 10.1.10.5
15:55:54 emulator: WARNING: Classic qemu does not support SMP. The hw.cpu.ncore option from your config file is ignored.
15:55:54 Content of hardware configuration file:
15:55:54   hw.cpu.arch = x86_64
15:55:54   hw.cpu.ncore = 2
15:55:54   hw.ramSize = 1024
15:55:54   hw.screen = multi-touch
15:55:54   hw.mainKeys = true
15:55:54   hw.trackBall = true
15:55:54   hw.keyboard = false
15:55:54   hw.keyboard.lid = false
15:55:54   hw.keyboard.charmap = qwerty2
15:55:54   hw.dPad = true
15:55:54   hw.gsmModem = true
15:55:54   hw.gps = true
15:55:54   hw.battery = true
15:55:54   hw.accelerometer = true
15:55:54   hw.audioInput = true
15:55:54   hw.audioOutput = true
15:55:54   hw.sdCard = true
15:55:54   hw.sdCard.path = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/sdcard.img
15:55:54   disk.cachePartition = true
15:55:54   disk.cachePartition.path = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/cache.img
15:55:54   disk.cachePartition.size = 66m
15:55:54   hw.lcd.width = 480
15:55:54   hw.lcd.height = 800
15:55:54   hw.lcd.depth = 16
15:55:54   hw.lcd.density = 160
15:55:54   hw.lcd.backlight = true
15:55:54   hw.gpu.enabled = false
15:55:54   hw.gpu.mode = off
15:55:54   hw.gpu.blacklisted = no
15:55:54   hw.initialOrientation = portrait
15:55:54   hw.camera.back = emulated
15:55:54   hw.camera.front = none
15:55:54   vm.heapSize = 192
15:55:54   hw.sensors.light = true
15:55:54   hw.sensors.pressure = true
15:55:54   hw.sensors.humidity = true
15:55:54   hw.sensors.proximity = true
15:55:54   hw.sensors.magnetic_field = true
15:55:54   hw.sensors.orientation = true
15:55:54   hw.sensors.temperature = true
15:55:54   hw.useext4 = true
15:55:54   kernel.path = /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//kernel-qemu
15:55:54   kernel.newDeviceNaming = yes
15:55:54   kernel.supportsYaffs2 = no
15:55:54   disk.ramdisk.path = /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//ramdisk.img
15:56:33   disk.systemPartition.initPath = /opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//system.img
15:56:33   disk.systemPartition.size = 1280m
15:56:33   disk.dataPartition.path = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/userdata-qemu.img
15:56:33   disk.dataPartition.initPath = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/userdata.img
15:56:33   disk.dataPartition.size = 2g
15:56:33   disk.snapStorage.path = /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/snapshots.img
15:56:33   avd.name = hudson_en-US_160_WVGA_android-23_x86_64_-jenkins
15:56:33 .
15:56:33 emulator: CPU Acceleration: DISABLED
15:56:33 emulator: CPU Acceleration status: KVM requires a CPU that supports vmx or svm
15:56:33 emulator: WARNING: x86_64 emulation may not work without hardware acceleration!
15:56:33 QEMU options list:
15:56:33 emulator: argv[00] = "/opt/android-sdk-linux25.2.5/tools/emulator64-x86"
15:56:33 emulator: argv[01] = "-audio"
15:56:33 emulator: argv[02] = "none"
15:56:33 emulator: argv[03] = "-dns-server"
15:56:33 emulator: argv[04] = "10.1.10.3,10.1.10.5"
15:56:33 emulator: argv[05] = "-serial"
15:56:33 emulator: argv[06] = "null"
15:56:33 emulator: argv[07] = "-serial"
15:56:33 emulator: argv[08] = "null"
15:56:33 emulator: argv[09] = "-boot-property"
15:56:33 emulator: argv[10] = "persist.sys.language=en"
15:56:33 emulator: argv[11] = "-boot-property"
15:56:33 emulator: argv[12] = "persist.sys.country=US"
15:56:33 emulator: argv[13] = "-android-ports"
15:56:33 emulator: argv[14] = "5758,5759"
15:56:33 emulator: argv[15] = "-android-report-console"
15:56:33 emulator: argv[16] = "tcp:5863,max=60"
15:56:33 emulator: argv[17] = "-disable-kvm"
15:56:33 emulator: argv[18] = "-android-hw"
15:56:33 emulator: argv[19] = "/var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/hardware-qemu.ini"
15:56:33 emulator: argv[20] = "-append"
15:56:33 emulator: argv[21] = "qemu=1 androidboot.hardware=goldfish clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=0 ndns=2"
15:56:33 Concatenated QEMU options:
15:56:33  /opt/android-sdk-linux25.2.5/tools/emulator64-x86 -audio none -dns-server 10.1.10.3,10.1.10.5 -serial null -serial null -boot-property persist.sys.language=en -boot-property persist.sys.country=US -android-ports 5758,5759 -android-report-console tcp:5863,max=60 -disable-kvm -android-hw /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/hardware-qemu.ini -append 'qemu=1 androidboot.hardware=goldfish clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=0 ndns=2'
15:56:33 emulator: Starting QEMU main loop
15:56:33 emulator: registered 'boot-properties' qemud service
15:56:33 emulator: Using kernel serial device prefix: ttyGF
15:56:33 emulator: AVD Name: hudson_en-US_160_WVGA_android-23_x86_64_-jenkins
15:56:33 emulator: Ramdisk image contains fstab.goldfish file
15:56:33 emulator: Found format of system partition: 'ext4'
15:56:33 emulator: Found format of userdata partition: 'ext4'
15:56:33 emulator: Found format of cache partition: 'ext4'
15:56:33 emulator: system partition format: ext4
15:56:33 emulator: nand_add_dev: system,size=0x50000000,file=/opt/android-sdk-linux25.2.5/system-images/android-23/default/x86_64//system.img,pagesize=512,extrasize=0,readonly
15:56:33 emulator: userdata partition format: ext4
15:56:33 emulator: nand_add_dev: userdata,size=0x80000000,file=/var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/userdata-qemu.img,pagesize=512,extrasize=0
15:56:33 emulator: cache partition format: ext4
15:56:33 emulator: Creating empty cache partition image at: /var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/cache.img
15:56:33 Creating filesystem with parameters:
15:56:33     Size: 69206016
15:56:33     Block size: 4096
15:56:33     Blocks per group: 32768
15:56:33     Inodes per group: 4224
15:56:33     Inode size: 256
15:56:33     Journal blocks: 1024
15:56:33     Label:
15:56:33     Blocks: 16896
15:56:33     Block groups: 1
15:56:33     Reserved block group size: 7
15:56:33 Created filesystem with 11/4224 inodes and 1302/16896 blocks
15:56:33 emulator: nand_add_dev: cache,size=0x4200000,file=/var/lib/jenkins/.android/avd/hudson_en-US_160_WVGA_android-23_x86_64_-jenkins.avd/cache.img,pagesize=512,extrasize=0
15:56:33 emulator: Adding boot property: 'dalvik.vm.heapsize' = '192m'
15:56:33 emulator: Adding boot property: 'qemu.sf.lcd_density' = '160'
15:56:33 emulator: Adding boot property: 'qemu.hw.mainkeys' = '1'
15:56:33 emulator: Adding boot property: 'qemu.sf.fake_camera' = 'back'
15:56:33 emulator: Found 2 DNS servers: 10.1.10.3 10.1.10.5
15:56:33 emulator: Kernel parameters: qemu=1 androidboot.hardware=goldfish clocksource=pit android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=0 ndns=2
15:56:33 emulator:     trying to find: /opt/android-sdk-linux25.2.5/tools/bios.bin
15:56:33
15:56:33 emulator:     trying to find: /opt/android-sdk-linux25.2.5/tools/lib/pc-bios/bios.bin
15:56:33
15:56:33 emulator:     trying to find: /opt/android-sdk-linux25.2.5/tools/vgabios-cirrus.bin
15:56:33
15:56:33 emulator:     trying to find: /opt/android-sdk-linux25.2.5/tools/lib/pc-bios/vgabios-cirrus.bin
15:56:33
15:56:34 emulator: Adding boot property: 'persist.sys.language' = 'en'
15:56:34 emulator: Adding boot property: 'persist.sys.country' = 'US'
15:56:34 emulator: (android_emulation_setup) using custom adb server port 5825
15:56:34 emulator: ro.adb.qemud invalid or not found, API >= 16, defaulting ro.adb.qemud = 0
15:56:34 emulator: (setup_console_and_adb_ports) trying console port 5758, adb port 5759 (legacy: true)
15:56:34 emulator: (android_console_start) initializing on port 5758
15:56:34 emulator: sent '0012host:emulator:5759' to ADB server
15:56:34 emulator: WARNING: Requested adb port (5759) is outside the recommended range [5555,5586]. ADB may not function properly for the emulator. See -help-port for details.
15:56:34 emulator: Listening for console connections on port: 5758
15:56:34 emulator: Serial number of this emulator (for ADB): emulator-5758
15:56:34 emulator: trying to find console-report client on tcp:5863
15:56:34 emulator: console port number sent to remote. resuming boot
15:56:34 [android] Emulator reported that the console is available on port 5,758
15:56:34 [android] Waiting for emulator to finish booting...
15:56:34 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
15:56:34 emulator: android_hw_fingerprint_init: fingerprint qemud listen service initialized
15:56:34
15:56:34 emulator: Skipping metrics reporting: No user opt-in.
15:58:04 ERROR: Timeout after 90000 milliseconds
15:58:04 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
15:59:47 ERROR: Timeout after 90000 milliseconds
15:59:47 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:01:31 ERROR: Timeout after 90000 milliseconds
16:01:31 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:03:14 ERROR: Timeout after 90000 milliseconds
16:03:14 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:04:58 ERROR: Timeout after 90000 milliseconds
16:04:58 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:06:42 ERROR: Timeout after 90000 milliseconds
16:06:42 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim
16:08:25 ERROR: Timeout after 90000 milliseconds
16:08:25 [android] Timed-out after waiting 720 seconds for emulator
16:08:39 [android] Stopping Android emulator
16:08:39 $ /opt/android-sdk-linux25.2.5/platform-tools/adb kill-server
16:08:40 Finished: NOT_BUILT

Any idea how to take my investigation forward?

Body:
It was already a year ago, but here is what I suggest for everybody who tries to set up Android build process in Jenkins:

Access Jenkins machine/server directly (e.g. via ssh) and try to launch emulator from terminal. In logs posted by OP, you can see that Jenkins tried to launch emulator:

15:56:34 $ /opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim

Maybe 90s (90000 miliseconds) isn't enough? You can launch following command on your server from terminal:

/opt/android-sdk-linux25.2.5/platform-tools/adb -s emulator-5758 wait-for-device shell getprop init.svc.bootanim

and measure how long it actually take.

If it takes too much time you may consider to keep emulator running on Jenkins machine and just assume it's always ready, so you need run following command to your UI/instrumented tests:

./gradlew connectedAndroidTest


问:
Modify NSFetchedResultsController fetchRequest in iOS 7
I found this answer : https://stackoverflow.com/a/4861732/1486928

I'm trying to do that but it won't let me assign a newly created NSFetchRequest and in the documentation it says :

@property (nonatomic, readonly) NSFetchRequest *fetchRequest

But in the next line it says :

Special Considerations : If you want to modify the fetch request, you must follow the steps described in “The Fetch Request.”

So which is it, am I allowed to modify it or not :/ ? Very confusing that the property is readonly and they say we can modify it :(

答:
Yes you can:

Create the NSFetchRequest instance and change its sort descriptor each time:

```<code>    let sortDescriptor = NSSortDescriptor(key: key, ascending: ascending)
    request.sortDescriptors = [sortDescriptor]

    do {
        try fetchedResultViewController?.performFetch()
    } catch let error as NSError {
        print("Error in fetch \(error)")
    }
</code>```

Read the apple document: https://developer.apple.com/reference/coredata/nsfetchedresultscontroller

Body:
Yes you can:

Create the NSFetchRequest instance and change its sort descriptor each time:

    let sortDescriptor = NSSortDescriptor(key: key, ascending: ascending)
    request.sortDescriptors = [sortDescriptor]

    do {
        try fetchedResultViewController?.performFetch()
    } catch let error as NSError {
        print("Error in fetch \(error)")
    }

Read the apple document: https://developer.apple.com/reference/coredata/nsfetchedresultscontroller

ContentLicense: CC BY-SA 4.0


问:
Regex pattern to separate string with semicolon and plus
Here I have used the below mentioned code.

```<code>MatchCollection matches = Regex.Matches(cellData, @"(^\[.*\]$|^\[.*\]_[0-9]*$)");
</code>```

The only this pattern is not doing is it's not separating the semicolon and plus from the main string.

A sample string is

```<code>[dbServer];[ciDBNAME];[dbLogin];[dbPasswd] AND [SIM_ErrorFound@1]_+[@IterationCount]
</code>```

I am trying to extract

```<code>[dbServer]
[ciDBNAME]
[dbLogin]
[dbPasswd]
[SIM_ErrorFound@1]
[@IterationCount]
</code>```

from the string.

答:
Your regex - (^\[.*\]$|^\[.*\]_[0-9]*$) - matches any full string that starts with [, then contains zero or more chars other than a newline, and ends with  ] (\]$) or with _ followed with 0+ digits (_[0-9]*$). You could also write the pattern as ^\[.*](?:_[0-9]*)?$ and it would work the same.

However, you need to match multiple substrings inside a larger string. Thus, you should have removed the ^ and $ anchors and retried. Then, you would find out that .* is too greedy and matches from the first [ up to the last ]. To fix that, it is best to use a negated character class solution. E.g. you may use [^][]* that matches 0+ chars other than [ and ].

Edit: It seems you need to get only the text inside square brackets.

You need to use a capturing group, a pair of unescaped parentheses around the part of the pattern you need to get and then access the value by the group ID (unnamed groups are numbered starting with 1 from left to right):

```<code>var results = Regex.Matches(s, @"\[([^][]+)]")
    .Cast<Match>()
    .Select(m => m.Groups[1].Value)
    .ToList();
</code>```

See the .NET regex demo

Body:
Here I have used the below mentioned code.

MatchCollection matches = Regex.Matches(cellData, @"(^\[.*\]$|^\[.*\]_[0-9]*$)");

The only this pattern is not doing is it's not separating the semicolon and plus from the main string.

A sample string is

[dbServer];[ciDBNAME];[dbLogin];[dbPasswd] AND [SIM_ErrorFound@1]_+[@IterationCount]

I am trying to extract

[dbServer]
[ciDBNAME]
[dbLogin]
[dbPasswd]
[SIM_ErrorFound@1]
[@IterationCount]

from the string.

Body:
Your regex - (^\[.*\]$|^\[.*\]_[0-9]*$) - matches any full string that starts with [, then contains zero or more chars other than a newline, and ends with  ] (\]$) or with _ followed with 0+ digits (_[0-9]*$). You could also write the pattern as ^\[.*](?:_[0-9]*)?$ and it would work the same.

However, you need to match multiple substrings inside a larger string. Thus, you should have removed the ^ and $ anchors and retried. Then, you would find out that .* is too greedy and matches from the first [ up to the last ]. To fix that, it is best to use a negated character class solution. E.g. you may use [^][]* that matches 0+ chars other than [ and ].

Edit: It seems you need to get only the text inside square brackets.

You need to use a capturing group, a pair of unescaped parentheses around the part of the pattern you need to get and then access the value by the group ID (unnamed groups are numbered starting with 1 from left to right):

var results = Regex.Matches(s, @"\[([^][]+)]")
    .Cast<Match>()
    .Select(m => m.Groups[1].Value)
    .ToList();

See the .NET regex demo


问:
Write corpus and vector to a csv file in R
```<code>dat <- read.csv("file.csv",header=F)$V2
doc.corpus <- Corpus(VectorSource(dat))
....
doc.corpus <- tm_map(doc.corpus, stripWhitespace)
sent <- ""
for(i in 2:length(doc.corpus)){
    sent[i] <- get_sentiment(get_sentences(as.character(doc.corpus[i])))
}
sent[1] = "sentiment"
</code>```

<p>I have to write sentiment and doc.corpus into a csv file as two columns in R. If it was just sent I would have done something like write.csv(sent,file = "MyData.csv") this. But how should I write a corpus to csv file.  </p>

答: dataframe <- data.frame(text=sapply(doc.corpus, identity),stringsAsFactors=F)</p>

Body:
dat <- read.csv("file.csv",header=F)$V2
doc.corpus <- Corpus(VectorSource(dat))
....
doc.corpus <- tm_map(doc.corpus, stripWhitespace)
sent <- ""
for(i in 2:length(doc.corpus)){
    sent[i] <- get_sentiment(get_sentences(as.character(doc.corpus[i])))
}
sent[1] = "sentiment"

I have to write sentiment and doc.corpus into a csv file as two columns in R. If it was just sent I would have done something like write.csv(sent,file = "MyData.csv") this. But how should I write a corpus to csv file.


问:
set value of input vield without showing it
when i click on span remove address it removes it from ui but not from the list and the printed value of removeItem is an empty string "".
and how can i pass the stringList to input value="" with id clientAdd without showing it on the input .

var stringList = [];
$("#clientAdd").keypress(function(e) {
  if (e.which === 13) {
    $(".target").append("" + "" + '+' + "" + this.value + "");
    stringList.push(this.value);
    this.value = "";
    console.log(stringList);
    $(document).on("click", ".removeAddress", function() {
      var removeItem = $(this).parent().parent().val();
      console.log(removeItem);
      stringList.splice($.inArray(removeItem, stringList), 1);
      $(this).parent().remove();

      console.log(stringList);
    });
  }
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
  <div class="form-group">
    <div class="col-md-12 col-sm-12">
      <label>Address *</label>
      <div class="target"></div>
      <input type="text" id="clientAdd" name="address" value="" class="form-control required">
    </div>
  </div>
</div></code>```

答:
Try this

Its parent text not a parent of parent .so you need get the text value of the parent use with $(this).parent().clone().children().remove().end().text() .It will get the parent text only .end() documentation

After removing clicked element .you are create the array  using remaining removeddress via map function

var stringList = [];
$("#clientAdd").keypress(function(e) {
  if (e.which === 13) {
    $(".target").append("" + "" + '+' + "" + this.value + "
");
    stringList.push(this.value);
    this.value = "";
    console.log(stringList);
    $(document).on("click", ".removeAddress", function() {
      var removeItem = $(this).parent().clone().children().remove().end().text();
      console.log(removeItem);
      stringList = $('.removeAddress').map(function(){
        return $(this).parent().clone().children().remove().end().text()
      }).get()
      $(this).parent().remove();
      console.log(stringList);
    });
  }
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="row">
  <div class="form-group">
    <div class="col-md-12 col-sm-12">
      <label>Address *</label>
      <div class="target"></div>
      <input type="text" id="clientAdd" name="address" value="" class="form-control required">
    </div>
  </div>
</div></code>```

Body:
when i click on span remove address it removes it from ui but not from the list and the printed value of removeItem is an empty string "".
and how can i pass the stringList to input value="" with id clientAdd without showing it on the input .

var stringList = [];
$("#clientAdd").keypress(function(e) {
  if (e.which === 13) {
    $(".target").append("" + "" + '+' + "" + this.value + "");
    stringList.push(this.value);
    this.value = "";
    console.log(stringList);
    $(document).on("click", ".removeAddress", function() {
      var removeItem = $(this).parent().parent().val();
      console.log(removeItem);
      stringList.splice($.inArray(removeItem, stringList), 1);
      $(this).parent().remove();

      console.log(stringList);
    });
  }
});

      Address *

      <input type="text" id="clientAdd" name="address" value="" class="form-control required">

Body:
Try this

Its parent text not a parent of parent .so you need get the text value of the parent use with $(this).parent().clone().children().remove().end().text() .It will get the parent text only .end() documentation

After removing clicked element .you are create the array  using remaining removeddress via map function

var stringList = [];
$("#clientAdd").keypress(function(e) {
  if (e.which === 13) {
    $(".target").append("<a href='#' class='tag'>" + "<span class='removeAddress'>" + '+' + "</span>" + this.value + "</a><br>");
    stringList.push(this.value);
    this.value = "";
    console.log(stringList);
    $(document).on("click", ".removeAddress", function() {
      var removeItem = $(this).parent().clone().children().remove().end().text();
      console.log(removeItem);
      stringList = $('.removeAddress').map(function(){
        return $(this).parent().clone().children().remove().end().text()
      }).get()
      $(this).parent().remove();
      console.log(stringList);
    });
  }
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="row">
  <div class="form-group">
    <div class="col-md-12 col-sm-12">
      <label>Address *</label>
      <div class="target"></div>
      <input type="text" id="clientAdd" name="address" value="" class="form-control required">
    </div>
  </div>
</div>


问:
Remove git mapping in Visual Studio 2015
This question has nothing to do with git itself; rather, it has to do with removing a binding/mapping to a git repository that Visual Studio 2015 (VS2015) has previously seen.

Here's a screen shot of the problem:

Notice that the remove button is grayed out (disabled). How can I remove this entry from the "Local Git Repositories" list?

答:
I spent some time to remove the git integration from my visual studio
 2015 project. any time i remove git from visual studio, and add TFS by following this  -- Tools -> option -> sourceControl -> plugin selection -> Visual Studio Team foundation server, it used to come back.

My solution was -

making the physical location of my project- Show all hidden files. you can do this by  show hidden files and folder option of windows.
then i realize, there was a hidden folder called .git something.
I kept a full back up of my project folder and also the git folder any other back up that necessary (I kept this back up incase my project breaks, so that i can go back to previous condition).

then i have deleted the hidden .git folder and any other .git related files.

then i try to Tools -> option -> sourceControl -> plugin selection -> Visual Studio Team foundation server.
then i open the project by visual studio- File -> open -> project/solution..

after that i noiticed in solution explorer , right clicking the solution namei see "Source control" option ,
and also in project - right click i see "Add soution to source control"..
and this time it didn't add solution to git..

also it is good to remove any git connection from your source control exploerer..if there is any..

so the main thing is that make sure there is no hidden git file in your project file and any other git extension.. hope this will be helpful to someone..


问:
How can a map be used to search the list of employe objects on the basis of different parameters?
I was asked this question in an interview today to which I explained the best to my abilities. But I still don't understand if this is the correct answer.

There is a cache which has Employee object as the key. The cache is populated with data from the database. Now there is a UI where we can enter either or all of the 3 attributes from the Employee object- name, ID and date of joining. Now this search would lead to multiple matching results.  To achieve this we need to check in the cache for the data.

To this I replied saying that my map would be of the structure - >. for the same EmployeeDetails object ,
 I will have multiple keys in the map(EmployeeDetails class is the object which contains complete detail of the Employee including address etc. Employee object just has 3 attributes - name, ID and date of joining.).

One of the objects with only name populated. The other with ID populated and the third one with date of joining populated. And now with the combination of attributes. So the map will be having the following keys -
Employee object with only the name populated -> Value would be list of of all the Employee objects with the same name.
Employee object with only the ID populated ->  Value would be list of of all the Employee objects with the same ID. Ideally the list size in this case should be 1.
Employee objects with only the Date Of Joining -> List of all the employee objects with the same date of joining.

Similarly there would be number of other Employee objects. For one such employee , all the three attributes - name , ID and date of joining would be populated.

In this way, I could have achieved the requirement to display all the employee results in case only some of the attributes out of name, ID and value is set on the UI.

I just want to understand if this is the correct way to achieve the outcome (display of list of matching results on the UI). Since I did not get selected, I believe there is something else which I possibly missed!

答: I would have a map with the Employee object as key and EmployeeDetails as value. I would get a get Collection of values from the map, create then a custom Comparator for each specific search, iterate through the values collection and use the comparator to compare the values. The search results should be added during the iteration in a results Collection.</p>


问:
Unique 8 digit incremental number
I'm trying to generate a number which will ultimately be stored as string(varchar). e.g.

First - ABC00000001

Second- ABC00000002
.........................
I am able to generate character string as expected. Now the problem is,incremental number.

What i am trying to do is get the last number stored e.g. ABC00000009 and generate the next number that is ABC00000010. How to do the same?

If i extract integers from this than i will get 1 or 10,how to make it according to 8 digit format.

Any help would really be appreciated.

答:
Of course if changing the table structure is not an option, you can try this:</p>

```<code>DECLARE @lastValue VARCHAR(15) = 'ABC00000001'
SELECT CONCAT('ABC',  RIGHT(100000000 + CAST(RIGHT(@lastValue, 8) AS INT) + 1, 8))

Result
-----------
ABC00000002
</code>```

Title: Unique 8 digit incremental number

Body:
Of course if changing the table structure is not an option, you can try this:

DECLARE @lastValue VARCHAR(15) = 'ABC00000001'
SELECT CONCAT('ABC',  RIGHT(100000000 + CAST(RIGHT(@lastValue, 8) AS INT) + 1, 8))

Result
-----------
ABC00000002


问:
Bouncy Castle takes long to generate RSA keypair
I have a Web API project where in one of the endpoints I am using Bouncy Castle library to generate RSA keypairs. While doing some load testing I started getting 504 (timeout error) after say 1500 parallel requests to my Web API. After some investigation I realized that it was Bouncy Castle which was causing it. So now I am thinking of preloading a table with say 1 million RSA keypairs and get them from that table when I need them. Below is my code where I am generating keypair using BC:

```<code>var r = new RsaKeyPairGenerator();
r.Init(new KeyGenerationParameters(new SecureRandom(), 1024));
var keyPair = r.GenerateKeyPair();
var publicKey = string.Empty;
using (var stream = new MemoryStream())
{
    var textWriter = new StreamWriter(stream);
    var pemWriter = new PemWriter(textWriter);
    pemWriter.WriteObject(keyPair.Public);
    pemWriter.Writer.Flush();
    stream.Position = 0;
    var sr = new StreamReader(stream);
    publicKey = sr.ReadToEnd();
    textWriter.Close();
}

var privateKey = string.Empty;
using (var stream = new MemoryStream())
{
    var textWriter = new StreamWriter(stream);
    var pemWriter = new PemWriter(textWriter);
    pemWriter.WriteObject(keyPair.Private);
    pemWriter.Writer.Flush();

    stream.Position = 0;
    var sr = new StreamReader(stream);
    privateKey = sr.ReadToEnd();
    textWriter.Close();
}
</code>```

So couple of questions, is there anything I am doing wrong in the code above (it works fine but if there is anything I am doing which is possibly causing the delay and can be avoided)? Also, if I go with the other approach (preloading the SQL table with 1 million keypairs), what would be the best way to populate the table with 1 million records? (preferably using ADO .net)

答:
If the key generator is doing a good job, it will be using a high-entropy random number generator. These will try and gather as much 'external' randomness from your server as they can, and a good generator will pause and possibly make an estimation of the randomness gathered.

Sources of randomness (if you don't have specific hardware available) are things like user inputs, hardware events (such as network traffic and USB interrupt) and timer jitter (which can change when CPU clocks change due to load).

On a server, it can be hard to gather enough entropy to generate good keys (due to lack of user input and a reduced number of peripherals).

Trying to generate a very large number of keys without special hardware is therefore going to being either slow or poor quality.

A hardware source (such as http://onerng.info/) would be preferable in this case.

Body:
I have a Web API project where in one of the endpoints I am using Bouncy Castle library to generate RSA keypairs. While doing some load testing I started getting 504 (timeout error) after say 1500 parallel requests to my Web API. After some investigation I realized that it was Bouncy Castle which was causing it. So now I am thinking of preloading a table with say 1 million RSA keypairs and get them from that table when I need them. Below is my code where I am generating keypair using BC:

var r = new RsaKeyPairGenerator();
r.Init(new KeyGenerationParameters(new SecureRandom(), 1024));
var keyPair = r.GenerateKeyPair();
var publicKey = string.Empty;
using (var stream = new MemoryStream())
{
    var textWriter = new StreamWriter(stream);
    var pemWriter = new PemWriter(textWriter);
    pemWriter.WriteObject(keyPair.Public);
    pemWriter.Writer.Flush();
    stream.Position = 0;
    var sr = new StreamReader(stream);
    publicKey = sr.ReadToEnd();
    textWriter.Close();
}

var privateKey = string.Empty;
using (var stream = new MemoryStream())
{
    var textWriter = new StreamWriter(stream);
    var pemWriter = new PemWriter(textWriter);
    pemWriter.WriteObject(keyPair.Private);
    pemWriter.Writer.Flush();

    stream.Position = 0;
    var sr = new StreamReader(stream);
    privateKey = sr.ReadToEnd();
    textWriter.Close();
}

So couple of questions, is there anything I am doing wrong in the code above (it works fine but if there is anything I am doing which is possibly causing the delay and can be avoided)? Also, if I go with the other approach (preloading the SQL table with 1 million keypairs), what would be the best way to populate the table with 1 million records? (preferably using ADO .net)


答:
Hi I just created a simple project. if you click on the button, it will generate random text on the textview2.

MainActivity.java

```<code>public class MainActivity extends AppCompatActivity {
TextView secondTextView;
String[] Textlist = { "Hello man  ", "sonam", "tashi","i am man","hellow world"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    secondTextView = (TextView) findViewById(R.id.textView2);

    Button mybtn = (Button) findViewById(R.id.btn);
    mybtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            changeTextView_two_text();

        }
    });
}

private void changeTextView_two_text() {

    Random random = new Random();
    String rand = Textlist[random.nextInt(Textlist.length)];
  //  String randomText = TextList[random.nextInt(TextList.length)];

    secondTextView.setText(rand);

}
</code>```

}

and activity_main.xml

```<code><LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.hello.googlemap.MainActivity">
<Button
    android:id="@+id/btn"
    android:text="click me"
    android:layout_width="368dp"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteY="0dp"
    tools:layout_editor_absoluteX="8dp" />
<TextView
    android:gravity="center"
    android:id="@+id/textView2"
    android:text="no text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/></LinearLayout>
</code>```

Hope this helps you.

Title: button doesn't click in android studio

Body:
Hi I just created a simple project. if you click on the button, it will generate random text on the textview2.

MainActivity.java

public class MainActivity extends AppCompatActivity {
TextView secondTextView;
String[] Textlist = { "Hello man  ", "sonam", "tashi","i am man","hellow world"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    secondTextView = (TextView) findViewById(R.id.textView2);

    Button mybtn = (Button) findViewById(R.id.btn);
    mybtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            changeTextView_two_text();

        }
    });
}

private void changeTextView_two_text() {

    Random random = new Random();
    String rand = Textlist[random.nextInt(Textlist.length)];
  //  String randomText = TextList[random.nextInt(TextList.length)];

    secondTextView.setText(rand);

}

}

and activity_main.xml

<LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.hello.googlemap.MainActivity">
<Button
    android:id="@+id/btn"
    android:text="click me"
    android:layout_width="368dp"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteY="0dp"
    tools:layout_editor_absoluteX="8dp" />
<TextView
    android:gravity="center"
    android:id="@+id/textView2"
    android:text="no text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/></LinearLayout>

Hope this helps you.


问:
C++ Check Internet Connection on Linux Ubuntu
Is there any way to check Internet Connection on Linux Ubuntu? Because  this one is only for Windows-- programmatically check whether my machine has internet access or not

Or Using Poco libraries.

答:
You can use route command in Linux to check

```<code>FILE *output;

if(!(output = popen("/sbin/route -n | grep -c '^0\\.0\\.0\\.0'","r")))
{
    return 1;
}
unsigned int i;
fscanf(output,"%u",&i);
if(i == 1)
       cerr<<"There is internet connection\n";
else if(i == 0)
       cerr<<"There is no internet connection\n";
pclose(output);
</code>```

You can find more information about it here.

Body:
You can use route command in Linux to check

FILE *output;

if(!(output = popen("/sbin/route -n | grep -c '^0\\.0\\.0\\.0'","r")))
{
    return 1;
}
unsigned int i;
fscanf(output,"%u",&i);
if(i == 1)
       cerr<<"There is internet connection\n";
else if(i == 0)
       cerr<<"There is no internet connection\n";
pclose(output);

You can find more information about it here.


问:
The Constructor is undefined? Enum error
```<code>public Tipo getTipo() {
    return this.Importo < 0.0 ? Tipo.USCITA : Tipo.ENTRATA;
}

public int compareTo(Movimento m) {
    if (this.idConto != this.idConto) {
        return this.idConto - this.idConto;
    }
    return this.DataMov.compareTo(this.DataMov);
}

public static enum Tipo {
    ENTRATA,// here i have this error : The constructor Movimento.Tipo() is undefined
    USCITA;// here is the same : The constructor Movimento.Tipo() is undefined

    private Tipo(String string2, int n2) {
    }
}
</code>```

I already have constructor that I need, what else I need to write?

答:
I am not sure how do you want to define enum. There are basically 2 solutions to this:

1. Define no parameter enum

```<code>public static enum Tipo {
    ENTRATA,
    USCITA;
}
</code>```

2. Define enum with parameters

```<code>public static enum Tipo {
    ENTRATA("Entrata", 1),
    USCITA("Uscita", 2);

    private String string;
    private int integer;

    private Tipo(String string, int integer) {
        this.string = string;
        this.integer = integer;
    }
}
</code>```

Body:
public Tipo getTipo() {
    return this.Importo < 0.0 ? Tipo.USCITA : Tipo.ENTRATA;
}

public int compareTo(Movimento m) {
    if (this.idConto != this.idConto) {
        return this.idConto - this.idConto;
    }
    return this.DataMov.compareTo(this.DataMov);
}

public static enum Tipo {
    ENTRATA,// here i have this error : The constructor Movimento.Tipo() is undefined
    USCITA;// here is the same : The constructor Movimento.Tipo() is undefined

    private Tipo(String string2, int n2) {
    }
}

I already have constructor that I need, what else I need to write?

Body:
I am not sure how do you want to define enum. There are basically 2 solutions to this:

1. Define no parameter enum

public static enum Tipo {
    ENTRATA,
    USCITA;
}

2. Define enum with parameters

public static enum Tipo {
    ENTRATA("Entrata", 1),
    USCITA("Uscita", 2);

    private String string;
    private int integer;

    private Tipo(String string, int integer) {
        this.string = string;
        this.integer = integer;
    }
}


问:
Typescript union type inference
How would I achieve type inference in the following case:</p>

```<code>type a = {
    foo: number;
    bar: string;
}

type b = {
    foo: string;
}

let baz: a | b;

if (baz.foo === 5) {
    baz.bar = "abc"; // baz type is still a | b, should be a
}
</code>```

答:
Apparently types cannot be inferred from the types of their properties, so you will need to define a type guard:

```<code>type a = {
    foo: number;
    bar: string;
}

type b = {
    foo: string;
}

let baz: a | b;

function isA(x: a | b): x is a {
    return typeof x.foo === 'number';
}

if (isA(baz) && baz.foo === 5) {
    baz.bar = "123";
}
</code>```

The isA type guard will tell TypeScript that you have checked bazs type yourself. Below is another way to achieve this with casts, but here you still need to cast baz for every usage which is probably not the best way to do this.

```<code>if ((baz as a).foo === 5) {
    (baz as a).z = "123";
}
</code>```

More information about type guards can be found in the TypeScript docs.

Title: Typescript union type inference

Body:
How would I achieve type inference in the following case:

type a = {
    foo: number;
    bar: string;
}

type b = {
    foo: string;
}

let baz: a | b;

if (baz.foo === 5) {
    baz.bar = "abc"; // baz type is still a | b, should be a
}

Body:
Apparently types cannot be inferred from the types of their properties, so you will need to define a type guard:

type a = {
    foo: number;
    bar: string;
}

type b = {
    foo: string;
}

let baz: a | b;

function isA(x: a | b): x is a {
    return typeof x.foo === 'number';
}

if (isA(baz) && baz.foo === 5) {
    baz.bar = "123";
}

The isA type guard will tell TypeScript that you have checked bazs type yourself. Below is another way to achieve this with casts, but here you still need to cast baz for every usage which is probably not the best way to do this.

if ((baz as a).foo === 5) {
    (baz as a).z = "123";
}

More information about type guards can be found in the TypeScript docs.


问:
How to do subtraction between two fields in a Table using an SQL query
I want to display the subtraction of two values from two different columns to a third column using a SQL query.

This is the table structure:

```<code>------------------------------------
id | subject | Time1 | Time2| Time3
------------------------------------
1  | String1 | 50    |  78  |
2  | String2 | 60    |  99  |
3  |         |       |      |
</code>```

I want to subtract Time2 from Time1 if both Time1 and Time2 has data and store in Time3.

Output should be like as

```<code>------------------------------------
id | subject | Time1 | Time2| Time3
------------------------------------
1  | String1 | 50    |  78  |  28
2  | String2 | 60    |  99  |  39
3  |         |       |      |
</code>```

Thanks!

答:
If Time1 and Time2 are datetime fields, then you should use TIMEDIFF function in MySQL to be able to correctly format the Time3 field.

```<code>SELECT id, subject, Time1, Time2, TIMEDIFF(Time1, Time2) as Time3
  FROM tbl
</code>```

http://www.w3resource.com/mysql/date-and-time-functions/mysql-timediff-function.php

Body:
I want to display the subtraction of two values from two different columns to a third column using a SQL query.

This is the table structure:

------------------------------------
id | subject | Time1 | Time2| Time3
------------------------------------
1  | String1 | 50    |  78  |
2  | String2 | 60    |  99  |
3  |         |       |      |

I want to subtract Time2 from Time1 if both Time1 and Time2 has data and store in Time3.

Output should be like as

------------------------------------
id | subject | Time1 | Time2| Time3
------------------------------------
1  | String1 | 50    |  78  |  28
2  | String2 | 60    |  99  |  39
3  |         |       |      |

Thanks!

Body:
If Time1 and Time2 are datetime fields, then you should use TIMEDIFF function in MySQL to be able to correctly format the Time3 field.

SELECT id, subject, Time1, Time2, TIMEDIFF(Time1, Time2) as Time3
  FROM tbl

http://www.w3resource.com/mysql/date-and-time-functions/mysql-timediff-function.php