问:
App crashes on resuming by clicking the app icon from menu
App launches normally. When I try to minimize it and reopen through the recent apps history, again it works fine. But when I minimize and try to re open it with the app icon, it crashes.

MainActivity.java

```<code>public class MainActivity extends AppCompatActivity implements ResetPasswordDialog.Listener {

public static final String TAG = MainActivity.class.getSimpleName();

private LoginFragment mLoginFragment;
private ResetPasswordDialog mResetPasswordDialog;

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

    if (savedInstanceState == null) {

        loadFragment();
    }
}

private void loadFragment(){

    if (mLoginFragment == null) {

        mLoginFragment = new LoginFragment();
    }
    getFragmentManager().beginTransaction().replace(R.id.fragmentFrame,mLoginFragment,LoginFragment.TAG).commit();
}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String data = intent.getData().getLastPathSegment();
    Log.d(TAG, "onNewIntent: "+data);

    mResetPasswordDialog = (ResetPasswordDialog) getFragmentManager().findFragmentByTag(ResetPasswordDialog.TAG);

    if (mResetPasswordDialog != null)
        mResetPasswordDialog.setToken(data);
}

@Override
public void onPasswordReset(String message) {

    showSnackBarMessage(message);
}

private void showSnackBarMessage(String message) {

    Snackbar.make(findViewById(R.id.activity_main),message, Snackbar.LENGTH_SHORT).show();

}
</code>```

}

AndroidManifest.xml

```<code><?xml version="1.0" encoding="utf-8"?>
</code>```

```<code><uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />

<!--singleTask => flag of launchMode -->
<application
    android:name="io.github.froger.xinger.InstaMaterialApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <activity
        android:name="io.github.froger.xinger.ui.activity.MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/AppTheme.LoginRegister"
        android:screenOrientation="portrait">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="learn2crack"
                android:scheme="http" />
        </intent-filter>
    </activity>

    <activity
        android:name="io.github.froger.xinger.ui.activity.DashboardActivity"
        android:screenOrientation="portrait">
    </activity>
    <activity
        android:name="io.github.froger.xinger.ui.activity.CommentsActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.TransparentActivity" />
    <activity
        android:name="io.github.froger.xinger.ui.activity.UserProfileActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.TransparentActivity"
        android:launchMode="singleInstance" />
    <activity
        android:name="io.github.froger.xinger.ui.activity.TakePhotoActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.TransparentActivity" />
    <activity
        android:name="io.github.froger.xinger.ui.activity.PublishActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme"
        android:windowSoftInputMode="stateHidden">

    </activity>
</application>
</code>```

Error

```<code>04-01 00:51:26.015 25525-25525/io.github.froger.instamaterial D/AndroidRuntime: Shutting down VM
04-01 00:51:26.016 25525-25525/io.github.froger.instamaterial E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: io.github.froger.instamaterial, PID: 25525
                                                                            java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
                                                                                at io.github.froger.xinger.ui.activity.MainActivity.onNewIntent(MainActivity.java:44)
                                                                                at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1245)
                                                                                at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1257)
                                                                                at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2804)
                                                                                at android.app.ActivityThread.performNewIntents(ActivityThread.java:2816)
                                                                                at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2825)
                                                                                at android.app.ActivityThread.-wrap15(ActivityThread.java)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1552)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:154)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
</code>```

答: The stack trace clearly indicates that the call to intent.getData() at line 44 of your MainActivity is returning a null. You should check for the null, and not try to interrogate the Intent if it is null.

Body:
App launches normally. When I try to minimize it and reopen through the recent apps history, again it works fine. But when I minimize and try to re open it with the app icon, it crashes.

MainActivity.java

public class MainActivity extends AppCompatActivity implements ResetPasswordDialog.Listener {

public static final String TAG = MainActivity.class.getSimpleName();

private LoginFragment mLoginFragment;
private ResetPasswordDialog mResetPasswordDialog;

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

    if (savedInstanceState == null) {

        loadFragment();
    }
}

private void loadFragment(){

    if (mLoginFragment == null) {

        mLoginFragment = new LoginFragment();
    }
    getFragmentManager().beginTransaction().replace(R.id.fragmentFrame,mLoginFragment,LoginFragment.TAG).commit();
}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String data = intent.getData().getLastPathSegment();
    Log.d(TAG, "onNewIntent: "+data);

    mResetPasswordDialog = (ResetPasswordDialog) getFragmentManager().findFragmentByTag(ResetPasswordDialog.TAG);

    if (mResetPasswordDialog != null)
        mResetPasswordDialog.setToken(data);
}

@Override
public void onPasswordReset(String message) {

    showSnackBarMessage(message);
}

private void showSnackBarMessage(String message) {

    Snackbar.make(findViewById(R.id.activity_main),message, Snackbar.LENGTH_SHORT).show();

}

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />

<application
    android:name="io.github.froger.xinger.InstaMaterialApplication"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <activity
        android:name="io.github.froger.xinger.ui.activity.MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/AppTheme.LoginRegister"
        android:screenOrientation="portrait">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="learn2crack"
                android:scheme="http" />
        </intent-filter>
    </activity>

    <activity
        android:name="io.github.froger.xinger.ui.activity.DashboardActivity"
        android:screenOrientation="portrait">
    </activity>
    <activity
        android:name="io.github.froger.xinger.ui.activity.CommentsActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.TransparentActivity" />
    <activity
        android:name="io.github.froger.xinger.ui.activity.UserProfileActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.TransparentActivity"
        android:launchMode="singleInstance" />
    <activity
        android:name="io.github.froger.xinger.ui.activity.TakePhotoActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.TransparentActivity" />
    <activity
        android:name="io.github.froger.xinger.ui.activity.PublishActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme"
        android:windowSoftInputMode="stateHidden">

    </activity>
</application>

Error

04-01 00:51:26.015 25525-25525/io.github.froger.instamaterial D/AndroidRuntime: Shutting down VM
04-01 00:51:26.016 25525-25525/io.github.froger.instamaterial E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: io.github.froger.instamaterial, PID: 25525
                                                                            java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
                                                                                at io.github.froger.xinger.ui.activity.MainActivity.onNewIntent(MainActivity.java:44)
                                                                                at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1245)
                                                                                at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1257)
                                                                                at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2804)
                                                                                at android.app.ActivityThread.performNewIntents(ActivityThread.java:2816)
                                                                                at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2825)
                                                                                at android.app.ActivityThread.-wrap15(ActivityThread.java)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1552)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:154)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)


来源: stackexchange

问:
arrays in arrays weird thing? Java
I have a variable B that stores how many user objects have been added in the array userarr. I'm using one line of code that adds a note that the user types in to the B element user object in the userarr array. Here it is:

```<code>userarr[login].notes[b] = tempnote;
</code>```

tempnote is a string variable that temporarily holds the note the user types in, and login stores the user number that you are logged in to. So it assigns the string variable tempnote to the login value user object in the user array, and in element b element in the notes array for that user.

But for some reason there is a problem with this line of code.
I know it is that line of code, because it happens right after you confirm you want to add that note, and there is a println right next to it that never appears.

Here is the method for the whole note thing:

```<code> public static void loggedin() {
     System.out.println("welcome, " + userarr[login].username + "!");
     do{
         System.out.println("type 'notes' to list current notes, type 'new' to add notes, type 'delete' to delete a note, or type 'exit' to exit the program.");
         switch(scan.nextLine()){
             case "exit":
                 System.out.println("exiting");
                 login = -1;
                 break;
              case "delete":

                 break;
              case "new":
                 System.out.println("\n\nType the note.");
                 String tempnote = scan.nextLine();
                 System.out.println("note is is now " + tempnote + ". is this what you want? type 'yes' to proceed, or 'no' to enter note again.");
                 String ch5 = scan.nextLine();
                 if (ch5.equals("no")) {
                     break;
                 } else {
                    userarr[login].notes[b] = tempnote;
                    System.out.println("note created!");
                    b += 1;
                 }
                 break;
             case "notes":
                 for (int i=0;i<b;i++) {
                     System.out.println("Note " + i + ":");
                     System.out.println(userarr[login].notes[i] + "\n");
                 }
                 break;
             default:
                 System.out.println("restarting.");

         };
     }while(login != -1);
}
</code>```

Here is the user object thing:

```<code> static class user extends TextGame {
     String username;
     int password;
     String[] notes;

     public user(String username, int password) {
        this.username = username;
        this.password = password;
     }

 }
 static user[] userarr = new user[10];
 static int a = 0;
 static int b = 0;
 static int login = -1;
</code>```

There is no error before i run it. when i get to the part that has the problem it says:

```<code>Exception in thread "main" java.lang.NullPointerException
at text.game.TextGame.loggedin(TextGame.java:80)
at text.game.TextGame.login(TextGame.java:53)
at text.game.TextGame.main(TextGame.java:135)
</code>```

anyone know the problem?

EDIT: It seems necessary to show the whole class, because there is apparently a lot more information people need to know. So here is the whole thing for you to have all the information you need:

```<code>package text.game;
import java.util.Scanner;

public class TextGame {

    static Scanner scan = new Scanner(System.in);
    static class user extends TextGame {
        String username;
        int password;
        String[] notes;

        public user(String username, int password) {
            this.username = username;
            this.password = password;
        }

     }
     static user[] userarr = new user[10];
     static int a = 0;
     static int b = 0;
     static int login = -1;

     public static void newuser() {
         System.out.println("\n\nType the username for this user.");
         String usernameA = scan.nextLine();
         System.out.println("Username is now " + usernameA + ". is this what you want? type 'yes' to proceed, or 'no' to enter username again.");
         if (scan.nextLine().equals("no")) {
             newuser();
         } else {
             System.out.println("\n\n type the password for this user. (numbers only.)");
             int passwordA = scan.nextInt();
             System.out.println("user is " + usernameA + " and password is " + passwordA + ". creating user.");
             userarr[a] = new user(usernameA, passwordA);
             System.out.println("user created!");
             a += 1;
         }
     }

     public static void login() {
         System.out.println("which account do you want to log into? type the name of a user, or type 'list' to view the users signed in.");
         String ch2 = scan.nextLine();
         if (ch2.equals("list")){
             for (int i=0;i<a;i++) {
                 System.out.println(userarr[i].username);
             }
         } else {
             for (int i=0;i<a;i++) {if ((userarr[i].username).equals(ch2)){
                  System.out.println("type the password for this account (USE NUMBERS ONLY).");
                  int ch4 = scan.nextInt();
                  if (ch4==userarr[i].password) {
                      System.out.println("logged in!"); login = i; loggedin();
                  }else{
                      System.out.print("incorrect password!");
                  }
             }
         }
     }
 }

 public static void loggedin() {
     System.out.println("welcome, " + userarr[login].username + "!");
     do{
         System.out.println("type 'notes' to list current notes, type 'new' to add notes, type 'delete' to delete a note, or type 'exit' to exit the program.");
         switch(scan.nextLine()){
             case "exit":
                 System.out.println("exiting");
                 login = -1;
                 break;
             case "delete":

                 break;
             case "new":
                 System.out.println("\n\nType the note.");
                 String tempnote = scan.nextLine();
                 System.out.println("note is is now " + tempnote + ". is this what you want? type 'yes' to proceed, or 'no' to enter note again.");
                String ch5 = scan.nextLine();
                if (ch5.equals("no")) {
                    break;
                } else {
                    userarr[login].notes[b] = tempnote;
                    System.out.println("note created!");
                    b += 1;
                }
                break;
            case "notes":
                for (int i=0;i<b;i++) {
                    System.out.println("Note " + i + ":");
                    System.out.println(userarr[login].notes[i] + "\n");
                }
                break;
            default:
                System.out.println("restarting.");

        };
    }while(login != -1);
}

 public static void main(String[] args) {
     do {
         System.out.println("Welcome to LINCOLN COMP console OS. Type 'new' to create a new user, type 'log' to log in to an existing user, or type 'exit' to leave.\nif you are asked a yes or no question, if you type something other than yes or no, it will default to yes.");
         String ch1 = scan.nextLine();
         switch (ch1) {
             case "new":
                 if (a==2) {
                     System.out.println("maximum users have been created. type a username to delete that user, type list to list users, or type back to return.");
                     String ch3 = scan.nextLine();
                     if (ch3.equals("list")) {
                         for (int i=0;i<a;i++) {
                              if (userarr[i].username==null) {
                                  System.out.println("undefined");
                              }else{
                                  System.out.println("\n" + userarr[i].username);
                              };
                          }
                     } else if (ch3.equals("back")) {
                         break;
                     } else {
                          for (int i=0;i<a;i++) {
                              if ((userarr[i].username).equals(ch3)){
                                  System.out.println("type the password for this account (USE NUMBERS ONLY).");
                                  int ch4 = scan.nextInt();
                                  if (ch4==userarr[i].password) {
                                      a --;
                                      userarr[i] = null;
                                      System.out.println("user deleted!");
                                      break;
                                  }else{
                                      System.out.println("incorrect password.");
                                      break;
                                  }

                              }else if (i==a-1) {
                                  System.out.println("user not found.");
                                  break;
                              }

                          }

                     }
                 }else {
                     System.out.println("Initializing user creation method:");
                     newuser();
                 }
                 break;
             case "log":
                 login();
                 break;
             case "exit":
                 System.out.println("Goodbye!");
                 System.exit(0);
                 break;
             case "debug":
                 for (int i=0;i<userarr.length;i++) {
                     System.out.println(userarr[i]);
                 }
                 break;
             default:
                 System.out.println("restarting.");
         }

     } while (true);
 }

}//Note from other user - Extra bracket?
</code>```

答:
Change

```<code>String[] notes;
</code>```

to something like:

```<code>String[] notes = new String[10];
</code>```

ContentLicense: CC BY-SA 3.0

Title: arrays in arrays weird thing? Java

Body:
I have a variable B that stores how many user objects have been added in the array userarr. I'm using one line of code that adds a note that the user types in to the B element user object in the userarr array. Here it is:

userarr[login].notes[b] = tempnote;

tempnote is a string variable that temporarily holds the note the user types in, and login stores the user number that you are logged in to. So it assigns the string variable tempnote to the login value user object in the user array, and in element b element in the notes array for that user.

But for some reason there is a problem with this line of code.
I know it is that line of code, because it happens right after you confirm you want to add that note, and there is a println right next to it that never appears.

Here is the method for the whole note thing:

 public static void loggedin() {
     System.out.println("welcome, " + userarr[login].username + "!");
     do{
         System.out.println("type 'notes' to list current notes, type 'new' to add notes, type 'delete' to delete a note, or type 'exit' to exit the program.");
         switch(scan.nextLine()){
             case "exit":
                 System.out.println("exiting");
                 login = -1;
                 break;
              case "delete":

                 break;
              case "new":
                 System.out.println("\n\nType the note.");
                 String tempnote = scan.nextLine();
                 System.out.println("note is is now " + tempnote + ". is this what you want? type 'yes' to proceed, or 'no' to enter note again.");
                 String ch5 = scan.nextLine();
                 if (ch5.equals("no")) {
                     break;
                 } else {
                    userarr[login].notes[b] = tempnote;
                    System.out.println("note created!");
                    b += 1;
                 }
                 break;
             case "notes":
                 for (int i=0;i<b;i++) {
                     System.out.println("Note " + i + ":");
                     System.out.println(userarr[login].notes[i] + "\n");
                 }
                 break;
             default:
                 System.out.println("restarting.");

         };
     }while(login != -1);
}

Here is the user object thing:

 static class user extends TextGame {
     String username;
     int password;
     String[] notes;

     public user(String username, int password) {
        this.username = username;
        this.password = password;
     }

 }
 static user[] userarr = new user[10];
 static int a = 0;
 static int b = 0;
 static int login = -1;

There is no error before i run it. when i get to the part that has the problem it says:

Exception in thread "main" java.lang.NullPointerException
at text.game.TextGame.loggedin(TextGame.java:80)
at text.game.TextGame.login(TextGame.java:53)
at text.game.TextGame.main(TextGame.java:135)

anyone know the problem?

EDIT: It seems necessary to show the whole class, because there is apparently a lot more information people need to know. So here is the whole thing for you to have all the information you need:

package text.game;
import java.util.Scanner;

public class TextGame {

    static Scanner scan = new Scanner(System.in);
    static class user extends TextGame {
        String username;
        int password;
        String[] notes;

        public user(String username, int password) {
            this.username = username;
            this.password = password;
        }

     }
     static user[] userarr = new user[10];
     static int a = 0;
     static int b = 0;
     static int login = -1;

     public static void newuser() {
         System.out.println("\n\nType the username for this user.");
         String usernameA = scan.nextLine();
         System.out.println("Username is now " + usernameA + ". is this what you want? type 'yes' to proceed, or 'no' to enter username again.");
         if (scan.nextLine().equals("no")) {
             newuser();
         } else {
             System.out.println("\n\n type the password for this user. (numbers only.)");
             int passwordA = scan.nextInt();
             System.out.println("user is " + usernameA + " and password is " + passwordA + ". creating user.");
             userarr[a] = new user(usernameA, passwordA);
             System.out.println("user created!");
             a += 1;
         }
     }

     public static void login() {
         System.out.println("which account do you want to log into? type the name of a user, or type 'list' to view the users signed in.");
         String ch2 = scan.nextLine();
         if (ch2.equals("list")){
             for (int i=0;i<a;i++) {
                 System.out.println(userarr[i].username);
             }
         } else {
             for (int i=0;i<a;i++) {if ((userarr[i].username).equals(ch2)){
                  System.out.println("type the password for this account (USE NUMBERS ONLY).");
                  int ch4 = scan.nextInt();
                  if (ch4==userarr[i].password) {
                      System.out.println("logged in!"); login = i; loggedin();
                  }else{
                      System.out.print("incorrect password!");
                  }
             }
         }
     }
 }

 public static void loggedin() {
     System.out.println("welcome, " + userarr[login].username + "!");
     do{
         System.out.println("type 'notes' to list current notes, type 'new' to add notes, type 'delete' to delete a note, or type 'exit' to exit the program.");
         switch(scan.nextLine()){
             case "exit":
                 System.out.println("exiting");
                 login = -1;
                 break;
             case "delete":

                 break;
             case "new":
                 System.out.println("\n\nType the note.");
                 String tempnote = scan.nextLine();
                 System.out.println("note is is now " + tempnote + ". is this what you want? type 'yes' to proceed, or 'no' to enter note again.");
                String ch5 = scan.nextLine();
                if (ch5.equals("no")) {
                    break;
                } else {
                    userarr[login].notes[b] = tempnote;
                    System.out.println("note created!");
                    b += 1;
                }
                break;
            case "notes":
                for (int i=0;i<b;i++) {
                    System.out.println("Note " + i + ":");
                    System.out.println(userarr[login].notes[i] + "\n");
                }
                break;
            default:
                System.out.println("restarting.");

        };
    }while(login != -1);
}

 public static void main(String[] args) {
     do {
         System.out.println("Welcome to LINCOLN COMP console OS. Type 'new' to create a new user, type 'log' to log in to an existing user, or type 'exit' to leave.\nif you are asked a yes or no question, if you type something other than yes or no, it will default to yes.");
         String ch1 = scan.nextLine();
         switch (ch1) {
             case "new":
                 if (a==2) {
                     System.out.println("maximum users have been created. type a username to delete that user, type list to list users, or type back to return.");
                     String ch3 = scan.nextLine();
                     if (ch3.equals("list")) {
                         for (int i=0;i<a;i++) {
                              if (userarr[i].username==null) {
                                  System.out.println("undefined");
                              }else{
                                  System.out.println("\n" + userarr[i].username);
                              };
                          }
                     } else if (ch3.equals("back")) {
                         break;
                     } else {
                          for (int i=0;i<a;i++) {
                              if ((userarr[i].username).equals(ch3)){
                                  System.out.println("type the password for this account (USE NUMBERS ONLY).");
                                  int ch4 = scan.nextInt();
                                  if (ch4==userarr[i].password) {
                                      a --;
                                      userarr[i] = null;
                                      System.out.println("user deleted!");
                                      break;
                                  }else{
                                      System.out.println("incorrect password.");
                                      break;
                                  }

                              }else if (i==a-1) {
                                  System.out.println("user not found.");
                                  break;
                              }

                          }

                     }
                 }else {
                     System.out.println("Initializing user creation method:");
                     newuser();
                 }
                 break;
             case "log":
                 login();
                 break;
             case "exit":
                 System.out.println("Goodbye!");
                 System.exit(0);
                 break;
             case "debug":
                 for (int i=0;i<userarr.length;i++) {
                     System.out.println(userarr[i]);
                 }
                 break;
             default:
                 System.out.println("restarting.");
         }

     } while (true);
 }

}//Note from other user - Extra bracket?

Body:
Change

String[] notes;

to something like:

String[] notes = new String[10];


问:
jquery css selector to match elements with id contains specific text after the last dot
I need to write css selector for jquery that matches elements with id that contains some text after the last dot.
Something that resembles  $(div[id*='cow']) - but stronger because I need it to match only if the text is after last dot.
So take everything after the last dot and see if the text contains my string.
For example text to look for - cow

```<code><div id ='my.very.first.cow'></div> // get it
<div id = 'my.very.first.cowandcat'></div> //get it
<div id = 'my.very.firstcow.andcat'></div> //DON'T get it - not after the last dot
</code>```

答:
You may extend the selectors using:

```<code>$.extend($.expr[':'],{......
</code>```

The snippet:

;(function($){
    $.extend($.expr[':'],{
        IdTextAfterLastDot: function(a, b, c) {
            var id = a.id;  // get current ID
            var sel = c.pop();  // get the parameter
            var idx = id.substr(id.lastIndexOf('.') + 1).indexOf(sel);
            //
            // If after last dot the id text starts with ....
            //
            return idx == 0;
        }
    });
})(jQuery);

//
// Use the new selector
//

$('div:IdTextAfterLastDot(cow)').each(function(idx, ele) {
    console.log('selected: ' + ele.id);
})```
<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 id ='my.very.first.cow'></div>
<div id = 'my.very.first.cowandcat'></div>
<div id = 'my.very.firstcow.andcat'></div></code>```

Body:
I need to write css selector for jquery that matches elements with id that contains some text after the last dot.
Something that resembles  $(div[id*='cow']) - but stronger because I need it to match only if the text is after last dot.
So take everything after the last dot and see if the text contains my string.
For example text to look for - cow

 // get it

 //get it

 //DON'T get it - not after the last dot

Body:
You may extend the selectors using:

$.extend($.expr[':'],{......

The snippet:

;(function($){
    $.extend($.expr[':'],{
        IdTextAfterLastDot: function(a, b, c) {
            var id = a.id;  // get current ID
            var sel = c.pop();  // get the parameter
            var idx = id.substr(id.lastIndexOf('.') + 1).indexOf(sel);
            //
            // If after last dot the id text starts with ....
            //
            return idx == 0;
        }
    });
})(jQuery);

//
// Use the new selector
//

$('div:IdTextAfterLastDot(cow)').each(function(idx, ele) {
    console.log('selected: ' + ele.id);
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id ='my.very.first.cow'></div>
<div id = 'my.very.first.cowandcat'></div>
<div id = 'my.very.firstcow.andcat'></div>


问:
How to perform operations with row arrays using numpy?
I have a matrix of absorbance values that I've pulled from a whole wack of spectra. I call this matrix "specdt"

Each row represents the values over multiple samples at a specific wavelength. I want to find the r^2 values of the regression against a seperate array of concentration values called "Concentration."

Here's what I have so far:

```<code>regression = []
for row in specdt:
    x = Concentration
    y = specdt[row,:]
    slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
    regression.append(r_value**2)

regression_n = numpy.asarray(regression)
numpy.savetxt("r2_2.csv", regression_n, delimiter=",")
</code>```

I get the error:

```<code>Traceback (most recent call last):
   file "blah blah", line 42, in <module>
   y = specdt[row,:]
InexError: arrays used as indices must be of integer (or boolean) type
</code>```

I suspected this is because "row" isn't an integer, so I tried to iterate over a "t" variable instead; no luck.

I suspect it's the way I'm trying to pull the row into the y values for linregress, but I can't seem to find another way to do this.

Any advice is greatly appreciated!

edit: I should mention that

```<code>y = row
</code>```

was the first thing i tried.

It gives me the following error:

```<code>Traceback (most recent call last):
  File "C:\Users\ME\Downloads\Personal\Spectrometer\test\Spectrum3.py", line 42, in <module>
    slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
  File "C:\Python27\lib\site-packages\scipy\stats\_stats_mstats_common.py", line 92, in linregress
    ssxm, ssxym, ssyxm, ssym = np.cov(x, y, bias=1).flat
  File "C:\Python27\lib\site-packages\numpy\lib\function_base.py", line 2432, in cov
    X = np.vstack((X, y))
  File "C:\Python27\lib\site-packages\numpy\core\shape_base.py", line 230, in vstack
    return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: all the input array dimensions except for the concatenation axis must match exactly
</code>```

The dimensions of the conncentration array and the row should be the same.

linregress works beautifully if I pull out a single column (I transposed specdt.) This is the working code, if that helps:

```<code>##take only column 26 or the values for 2268; print stuff
#Absorbance2268 = spectral_data[:, 25]

#print(Absorbance2268.shape)
#print(Absorbance2268)
#
##manual entry of concentration values + array info
#conc =[0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,8,8,8,8,8,10,10,10,10,10,4,4,4,4,4]
#Concentration = numpy.asarray(conc)
#
#print(Concentration.shape)
#print(Concentration)
#
##performing linear regression.
#x = Concentration
#y = Absorbance2268
#
#slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
#
#print "r-squared:", r_value**2
</code>```

答:
```<code>for y in specdt:    # <---
    x = Concentration
    slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
</code>```

The for loop gives the content of the rows themselves already. If you want the row index, use

```<code>for row, y in enumerate(specdt):
    ...
</code>```

Body:
I have a matrix of absorbance values that I've pulled from a whole wack of spectra. I call this matrix "specdt"

Each row represents the values over multiple samples at a specific wavelength. I want to find the r^2 values of the regression against a seperate array of concentration values called "Concentration."

Here's what I have so far:

regression = []
for row in specdt:
    x = Concentration
    y = specdt[row,:]
    slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
    regression.append(r_value**2)

regression_n = numpy.asarray(regression)
numpy.savetxt("r2_2.csv", regression_n, delimiter=",")

I get the error:

Traceback (most recent call last):
   file "blah blah", line 42, in <module>
   y = specdt[row,:]
InexError: arrays used as indices must be of integer (or boolean) type

I suspected this is because "row" isn't an integer, so I tried to iterate over a "t" variable instead; no luck.

I suspect it's the way I'm trying to pull the row into the y values for linregress, but I can't seem to find another way to do this.

Any advice is greatly appreciated!

edit: I should mention that

y = row

was the first thing i tried.

It gives me the following error:

Traceback (most recent call last):
  File "C:\Users\ME\Downloads\Personal\Spectrometer\test\Spectrum3.py", line 42, in <module>
    slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
  File "C:\Python27\lib\site-packages\scipy\stats\_stats_mstats_common.py", line 92, in linregress
    ssxm, ssxym, ssyxm, ssym = np.cov(x, y, bias=1).flat
  File "C:\Python27\lib\site-packages\numpy\lib\function_base.py", line 2432, in cov
    X = np.vstack((X, y))
  File "C:\Python27\lib\site-packages\numpy\core\shape_base.py", line 230, in vstack
    return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: all the input array dimensions except for the concatenation axis must match exactly

The dimensions of the conncentration array and the row should be the same.

linregress works beautifully if I pull out a single column (I transposed specdt.) This is the working code, if that helps:

##take only column 26 or the values for 2268; print stuff
#Absorbance2268 = spectral_data[:, 25]

#print(Absorbance2268.shape)
#print(Absorbance2268)
#
##manual entry of concentration values + array info
#conc =[0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,8,8,8,8,8,10,10,10,10,10,4,4,4,4,4]
#Concentration = numpy.asarray(conc)
#
#print(Concentration.shape)
#print(Concentration)
#
##performing linear regression.
#x = Concentration
#y = Absorbance2268
#
#slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
#
#print "r-squared:", r_value**2

Body:
for y in specdt:    # <---
    x = Concentration
    slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)

The for loop gives the content of the rows themselves already. If you want the row index, use

for row, y in enumerate(specdt):
    ...


问:
Aurelia compose with globalResources
Our plan is the following: A dashboard with webparts. We plan on develop many different "webparts" (as custom elements), and later, based on role or preferences we will show just a selection of the availible webparts.

Say I have the following custom elements in a dashboard.

```<code><template>
   <my-webpart1 state.bind="state"></my-webpart1>
   <my-webpart2 state.bind="state"></my-webpart2>
   <my-webpart3 state.bind="state"></my-webpart3>
   <my-webpart4 state.bind="state"></my-webpart4>
   <my-webpart5 state.bind="state"></my-webpart5>
</template>
</code>```

Is it possible to iterate over the names instead?

```<code><div repeat.for="webpartname of manager.webparts">
  <compose view-model="${webpartname}" ></compose>
</div>
</code>```

First problem is that the webparts are developed in different features and is registered using .globalResources() - how can I get the url?

Then the second problem is how to do the binding. I've not started on that yet.

Any ideas on how to solve this?

Regards

Larsi

答: Use if.bind or show.bind attributes on each part instead of using compose.

Title: Aurelia compose with globalResources

Body:
Our plan is the following: A dashboard with webparts. We plan on develop many different "webparts" (as custom elements), and later, based on role or preferences we will show just a selection of the availible webparts.

Say I have the following custom elements in a dashboard.

<template>
   <my-webpart1 state.bind="state"></my-webpart1>
   <my-webpart2 state.bind="state"></my-webpart2>
   <my-webpart3 state.bind="state"></my-webpart3>
   <my-webpart4 state.bind="state"></my-webpart4>
   <my-webpart5 state.bind="state"></my-webpart5>
</template>

Is it possible to iterate over the names instead?

  <compose view-model="${webpartname}" ></compose>

First problem is that the webparts are developed in different features and is registered using .globalResources() - how can I get the url?

Then the second problem is how to do the binding. I've not started on that yet.

Any ideas on how to solve this?

Regards

Larsi


问:
Output string with leading spaces to log, keeping the spaces
How can I print leading spaces to the log?

When I do something like

```<code>data _null_;
  x = '  Hello, world!';
  put x;
run;
</code>```

The result is

```<code>2522  data _null_;
2523    x = '  Hello, world!';
2524    putlog x;
2525  run;

Hello, world!
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
</code>```

I looked through the PUT documentation, but nothing stood out to me.  It seems like using a format, such as $CHARw., might work.  However, that would require knowing the length of the string ahead of time.

I would like the log output to look like this:

```<code>  Hello, world!  (<--edited by hand to display leading spaces)
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
</code>```

答:
So you can use @n pointer control if you just want to add leading spaces.

```<code>putlog @3 x ;
</code>```

If you want to conditionally build X such that it only sometimes has leading spaces then you could use the $varying. format. You will need to define a variable with the length you want it to write, but you do not need to modify the format used.

```<code>166  data _null_;
167    do i=3 to 1 by -1 ;
168       x = substr('  Hello, world!',i);
169       len = length(x);
170       putlog x $varying80. len ;
171    end;
172  run;

Hello, world!
 Hello, world!
  Hello, world!
</code>```

Body:
How can I print leading spaces to the log?

When I do something like

data _null_;
  x = '  Hello, world!';
  put x;
run;

The result is

2522  data _null_;
2523    x = '  Hello, world!';
2524    putlog x;
2525  run;

Hello, world!
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

I looked through the PUT documentation, but nothing stood out to me.  It seems like using a format, such as $CHARw., might work.  However, that would require knowing the length of the string ahead of time.

I would like the log output to look like this:

  Hello, world!  (<--edited by hand to display leading spaces)
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

Body:
So you can use @n pointer control if you just want to add leading spaces.

putlog @3 x ;

If you want to conditionally build X such that it only sometimes has leading spaces then you could use the $varying. format. You will need to define a variable with the length you want it to write, but you do not need to modify the format used.

166  data _null_;
167    do i=3 to 1 by -1 ;
168       x = substr('  Hello, world!',i);
169       len = length(x);
170       putlog x $varying80. len ;
171    end;
172  run;

Hello, world!
 Hello, world!
  Hello, world!


问:
How do I call secondary window using a pushbutton
I am new to programming and PyQt5. I have designed a UI with Qt designer and successfully converted them to python scripts. However, I need a way to call  another window using a pushbutton in my main window. I have been racking my brains (and the internet) for the past 16 hours and still cannot find a solution. Also it appears that my pushbuttons do not run programs they are connected to.

This is the main code that calls the primary gui saved as primary.py

```<code>    # -*- coding: utf-8 -*-

from PyQt5 import QtWidgets
from primary import Ui_Primary
import sys

class Primary(QtWidgets.QMainWindow, Ui_Primary):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        Ui_Primary().setupUi(self)

if __name__== '__main__':
    app = QtWidgets.QApplication(sys.argv)
    myapp = Primary()
    myapp.show()
    app.aboutToQuit.connect(app.deleteLater)
    app.exec_()
</code>```

Below is the code for my primary gui

```<code>from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Primary(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(250, 300)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(250, 300))
        MainWindow.setMaximumSize(QtCore.QSize(250, 300))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setContentsMargins(5, 10, 5, 5)
        self.verticalLayout.setSpacing(10)
        self.verticalLayout.setObjectName("verticalLayout")
        self.setupPush = QtWidgets.QPushButton(self.centralwidget)
        self.setupPush.setObjectName("setupPush")
        self.verticalLayout.addWidget(self.setupPush)
        self.line_5 = QtWidgets.QFrame(self.centralwidget)
        self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_5.setObjectName("line_5")
        self.verticalLayout.addWidget(self.line_5)
        self.nodePropPush = QtWidgets.QPushButton(self.centralwidget)
        self.nodePropPush.setObjectName("nodePropPush")
        self.verticalLayout.addWidget(self.nodePropPush)
        self.line_4 = QtWidgets.QFrame(self.centralwidget)
        self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.verticalLayout.addWidget(self.line_4)
        self.elPropLabel = QtWidgets.QPushButton(self.centralwidget)
        self.elPropLabel.setObjectName("elPropLabel")
        self.verticalLayout.addWidget(self.elPropLabel)
        self.line_3 = QtWidgets.QFrame(self.centralwidget)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.verticalLayout.addWidget(self.line_3)
        self.bcPush = QtWidgets.QPushButton(self.centralwidget)
        self.bcPush.setObjectName("bcPush")
        self.verticalLayout.addWidget(self.bcPush)
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.verticalLayout.addWidget(self.line_2)
        self.solvePush = QtWidgets.QPushButton(self.centralwidget)
        self.solvePush.setObjectName("solvePush")
        self.verticalLayout.addWidget(self.solvePush)
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.verticalLayout.addWidget(self.line)
        self.resultPush = QtWidgets.QPushButton(self.centralwidget)
        self.resultPush.setObjectName("resultPush")
        self.verticalLayout.addWidget(self.resultPush)
        self.verticalLayout_2.addLayout(self.verticalLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 250, 21))
        self.menubar.setObjectName("menubar")
        self.menuFEA = QtWidgets.QMenu(self.menubar)
        self.menuFEA.setObjectName("menuFEA")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionExit = QtWidgets.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.menuFEA.addAction(self.actionExit)
        self.menubar.addAction(self.menuFEA.menuAction())
        self.setupPush.clicked.connect(self.code)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "FEA - Bar 2D"))
        MainWindow.setStatusTip(_translate("MainWindow", "Ready"))
        self.setupPush.setStatusTip(_translate("MainWindow", "Setup"))
        self.setupPush.setText(_translate("MainWindow", "Setup"))
        self.nodePropPush.setStatusTip(_translate("MainWindow", "Input node properties"))
        self.nodePropPush.setText(_translate("MainWindow", "Node Properties"))
        self.elPropLabel.setStatusTip(_translate("MainWindow", "Input element properties"))
        self.elPropLabel.setText(_translate("MainWindow", "Element Properties"))
        self.bcPush.setStatusTip(_translate("MainWindow", "Input boundary conditions"))
        self.bcPush.setText(_translate("MainWindow", "Boundary Conditons"))
        self.solvePush.setStatusTip(_translate("MainWindow", "Solve"))
        self.solvePush.setText(_translate("MainWindow", "Solve"))
        self.resultPush.setStatusTip(_translate("MainWindow", "List solution results"))
        self.resultPush.setText(_translate("MainWindow", "List Results"))
        self.menuFEA.setTitle(_translate("MainWindow", "FEA"))
        self.actionExit.setText(_translate("MainWindow", "Exit"))
        self.actionExit.setStatusTip(_translate("MainWindow", "Exit"))
        self.actionExit.setShortcut(_translate("MainWindow", "Ctrl+Q"))

    def code(self):
        print('Finally, I work! :)')
</code>```

Below is the gui I would like to call with my setup pushbutton name above as setupPush

```<code>from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_SetUp(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(300, 190)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(300, 190))
        MainWindow.setMaximumSize(QtCore.QSize(300, 190))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.formLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.formLayoutWidget.setGeometry(QtCore.QRect(20, 10, 261, 101))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(5, 10, 5, 5)
        self.formLayout.setSpacing(10)
        self.formLayout.setObjectName("formLayout")
        self.nnodeLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.nnodeLabel.setObjectName("nnodeLabel")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.nnodeLabel)
        self.nelLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.nelLabel.setObjectName("nelLabel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.nelLabel)
        self.ndofLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.ndofLabel.setObjectName("ndofLabel")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.ndofLabel)
        self.ndof = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.ndof.setObjectName("ndof")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.ndof)
        self.nel = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.nel.setObjectName("nel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.nel)
        self.nnode = QtWidgets.QLineEdit(self.formLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.nnode.sizePolicy().hasHeightForWidth())
        self.nnode.setSizePolicy(sizePolicy)
        self.nnode.setObjectName("nnode")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.nnode)
        self.ndof.raise_()
        self.nnodeLabel.raise_()
        self.nelLabel.raise_()
        self.nel.raise_()
        self.nnode.raise_()
        self.ndofLabel.raise_()
        self.mainOkPush = QtWidgets.QPushButton(self.centralwidget)
        self.mainOkPush.setGeometry(QtCore.QRect(20, 120, 75, 23))
        self.mainOkPush.setToolTip("")
        self.mainOkPush.setObjectName("mainOkPush")
        self.mainCancelPush = QtWidgets.QPushButton(self.centralwidget)
        self.mainCancelPush.setGeometry(QtCore.QRect(210, 120, 75, 23))
        self.mainCancelPush.setObjectName("mainCancelPush")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 300, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Main Window"))
        self.nnodeLabel.setText(_translate("MainWindow", "Number of Nodes"))
        self.nelLabel.setText(_translate("MainWindow", "Number of Elements"))
        self.ndofLabel.setText(_translate("MainWindow", "Number of DOF per node"))
        self.mainOkPush.setStatusTip(_translate("MainWindow", "Save and continue"))
        self.mainOkPush.setText(_translate("MainWindow", "OK"))
        self.mainCancelPush.setStatusTip(_translate("MainWindow", "Cancel"))
        self.mainCancelPush.setText(_translate("MainWindow", "Cancel"))
</code>```

答:
The signal connection must be given in the Primary class or a class that inherits from QObject. Also the way you use Ui_primary and its methods is incorrect. Finally you must create a class that can use your design, this is called SetUp, and then we connect the show function to the button (I used the button nodePropPush).

```<code>class SetUp(QtWidgets.QMainWindow, Ui_SetUp):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)

class Primary(QtWidgets.QMainWindow, Ui_Primary):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.setupPush.clicked.connect(self.code)

        s = SetUp(self)

        self.nodePropPush.clicked.connect(s.show)

    def code(self):
        print('Finally, I work! :)')
</code>```

complete code:

```<code>from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_SetUp(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(300, 190)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(300, 190))
        MainWindow.setMaximumSize(QtCore.QSize(300, 190))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.formLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.formLayoutWidget.setGeometry(QtCore.QRect(20, 10, 261, 101))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(5, 10, 5, 5)
        self.formLayout.setSpacing(10)
        self.formLayout.setObjectName("formLayout")
        self.nnodeLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.nnodeLabel.setObjectName("nnodeLabel")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.nnodeLabel)
        self.nelLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.nelLabel.setObjectName("nelLabel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.nelLabel)
        self.ndofLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.ndofLabel.setObjectName("ndofLabel")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.ndofLabel)
        self.ndof = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.ndof.setObjectName("ndof")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.ndof)
        self.nel = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.nel.setObjectName("nel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.nel)
        self.nnode = QtWidgets.QLineEdit(self.formLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.nnode.sizePolicy().hasHeightForWidth())
        self.nnode.setSizePolicy(sizePolicy)
        self.nnode.setObjectName("nnode")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.nnode)
        self.ndof.raise_()
        self.nnodeLabel.raise_()
        self.nelLabel.raise_()
        self.nel.raise_()
        self.nnode.raise_()
        self.ndofLabel.raise_()
        self.mainOkPush = QtWidgets.QPushButton(self.centralwidget)
        self.mainOkPush.setGeometry(QtCore.QRect(20, 120, 75, 23))
        self.mainOkPush.setToolTip("")
        self.mainOkPush.setObjectName("mainOkPush")
        self.mainCancelPush = QtWidgets.QPushButton(self.centralwidget)
        self.mainCancelPush.setGeometry(QtCore.QRect(210, 120, 75, 23))
        self.mainCancelPush.setObjectName("mainCancelPush")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 300, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Main Window"))
        self.nnodeLabel.setText(_translate("MainWindow", "Number of Nodes"))
        self.nelLabel.setText(_translate("MainWindow", "Number of Elements"))
        self.ndofLabel.setText(_translate("MainWindow", "Number of DOF per node"))
        self.mainOkPush.setStatusTip(_translate("MainWindow", "Save and continue"))
        self.mainOkPush.setText(_translate("MainWindow", "OK"))
        self.mainCancelPush.setStatusTip(_translate("MainWindow", "Cancel"))
        self.mainCancelPush.setText(_translate("MainWindow", "Cancel"))

class Ui_Primary(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(250, 300)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(250, 300))
        MainWindow.setMaximumSize(QtCore.QSize(250, 300))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setContentsMargins(5, 10, 5, 5)
        self.verticalLayout.setSpacing(10)
        self.verticalLayout.setObjectName("verticalLayout")
        self.setupPush = QtWidgets.QPushButton(self.centralwidget)
        self.setupPush.setObjectName("setupPush")
        self.verticalLayout.addWidget(self.setupPush)
        self.line_5 = QtWidgets.QFrame(self.centralwidget)
        self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_5.setObjectName("line_5")
        self.verticalLayout.addWidget(self.line_5)
        self.nodePropPush = QtWidgets.QPushButton(self.centralwidget)
        self.nodePropPush.setObjectName("nodePropPush")
        self.verticalLayout.addWidget(self.nodePropPush)
        self.line_4 = QtWidgets.QFrame(self.centralwidget)
        self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.verticalLayout.addWidget(self.line_4)
        self.elPropLabel = QtWidgets.QPushButton(self.centralwidget)
        self.elPropLabel.setObjectName("elPropLabel")
        self.verticalLayout.addWidget(self.elPropLabel)
        self.line_3 = QtWidgets.QFrame(self.centralwidget)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.verticalLayout.addWidget(self.line_3)
        self.bcPush = QtWidgets.QPushButton(self.centralwidget)
        self.bcPush.setObjectName("bcPush")
        self.verticalLayout.addWidget(self.bcPush)
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.verticalLayout.addWidget(self.line_2)
        self.solvePush = QtWidgets.QPushButton(self.centralwidget)
        self.solvePush.setObjectName("solvePush")
        self.verticalLayout.addWidget(self.solvePush)
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.verticalLayout.addWidget(self.line)
        self.resultPush = QtWidgets.QPushButton(self.centralwidget)
        self.resultPush.setObjectName("resultPush")
        self.verticalLayout.addWidget(self.resultPush)
        self.verticalLayout_2.addLayout(self.verticalLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 250, 21))
        self.menubar.setObjectName("menubar")
        self.menuFEA = QtWidgets.QMenu(self.menubar)
        self.menuFEA.setObjectName("menuFEA")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionExit = QtWidgets.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.menuFEA.addAction(self.actionExit)
        self.menubar.addAction(self.menuFEA.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "FEA - Bar 2D"))
        MainWindow.setStatusTip(_translate("MainWindow", "Ready"))
        self.setupPush.setStatusTip(_translate("MainWindow", "Setup"))
        self.setupPush.setText(_translate("MainWindow", "Setup"))
        self.nodePropPush.setStatusTip(_translate("MainWindow", "Input node properties"))
        self.nodePropPush.setText(_translate("MainWindow", "Node Properties"))
        self.elPropLabel.setStatusTip(_translate("MainWindow", "Input element properties"))
        self.elPropLabel.setText(_translate("MainWindow", "Element Properties"))
        self.bcPush.setStatusTip(_translate("MainWindow", "Input boundary conditions"))
        self.bcPush.setText(_translate("MainWindow", "Boundary Conditons"))
        self.solvePush.setStatusTip(_translate("MainWindow", "Solve"))
        self.solvePush.setText(_translate("MainWindow", "Solve"))
        self.resultPush.setStatusTip(_translate("MainWindow", "List solution results"))
        self.resultPush.setText(_translate("MainWindow", "List Results"))
        self.menuFEA.setTitle(_translate("MainWindow", "FEA"))
        self.actionExit.setText(_translate("MainWindow", "Exit"))
        self.actionExit.setStatusTip(_translate("MainWindow", "Exit"))
        self.actionExit.setShortcut(_translate("MainWindow", "Ctrl+Q"))

import sys

class SetUp(QtWidgets.QMainWindow, Ui_SetUp):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)

class Primary(QtWidgets.QMainWindow, Ui_Primary):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.setupPush.clicked.connect(self.code)

        s = SetUp(self)

        self.nodePropPush.clicked.connect(s.show)

    def code(self):
        print('Finally, I work! :)')

if __name__== '__main__':
    app = QtWidgets.QApplication(sys.argv)
    myapp = Primary()
    myapp.show()
    app.aboutToQuit.connect(app.deleteLater)
    app.exec_()
</code>```

Body:
I am new to programming and PyQt5. I have designed a UI with Qt designer and successfully converted them to python scripts. However, I need a way to call  another window using a pushbutton in my main window. I have been racking my brains (and the internet) for the past 16 hours and still cannot find a solution. Also it appears that my pushbuttons do not run programs they are connected to.

This is the main code that calls the primary gui saved as primary.py

    # -*- coding: utf-8 -*-

from PyQt5 import QtWidgets
from primary import Ui_Primary
import sys

class Primary(QtWidgets.QMainWindow, Ui_Primary):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        Ui_Primary().setupUi(self)

if __name__== '__main__':
    app = QtWidgets.QApplication(sys.argv)
    myapp = Primary()
    myapp.show()
    app.aboutToQuit.connect(app.deleteLater)
    app.exec_()

Below is the code for my primary gui

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Primary(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(250, 300)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(250, 300))
        MainWindow.setMaximumSize(QtCore.QSize(250, 300))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setContentsMargins(5, 10, 5, 5)
        self.verticalLayout.setSpacing(10)
        self.verticalLayout.setObjectName("verticalLayout")
        self.setupPush = QtWidgets.QPushButton(self.centralwidget)
        self.setupPush.setObjectName("setupPush")
        self.verticalLayout.addWidget(self.setupPush)
        self.line_5 = QtWidgets.QFrame(self.centralwidget)
        self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_5.setObjectName("line_5")
        self.verticalLayout.addWidget(self.line_5)
        self.nodePropPush = QtWidgets.QPushButton(self.centralwidget)
        self.nodePropPush.setObjectName("nodePropPush")
        self.verticalLayout.addWidget(self.nodePropPush)
        self.line_4 = QtWidgets.QFrame(self.centralwidget)
        self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.verticalLayout.addWidget(self.line_4)
        self.elPropLabel = QtWidgets.QPushButton(self.centralwidget)
        self.elPropLabel.setObjectName("elPropLabel")
        self.verticalLayout.addWidget(self.elPropLabel)
        self.line_3 = QtWidgets.QFrame(self.centralwidget)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.verticalLayout.addWidget(self.line_3)
        self.bcPush = QtWidgets.QPushButton(self.centralwidget)
        self.bcPush.setObjectName("bcPush")
        self.verticalLayout.addWidget(self.bcPush)
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.verticalLayout.addWidget(self.line_2)
        self.solvePush = QtWidgets.QPushButton(self.centralwidget)
        self.solvePush.setObjectName("solvePush")
        self.verticalLayout.addWidget(self.solvePush)
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.verticalLayout.addWidget(self.line)
        self.resultPush = QtWidgets.QPushButton(self.centralwidget)
        self.resultPush.setObjectName("resultPush")
        self.verticalLayout.addWidget(self.resultPush)
        self.verticalLayout_2.addLayout(self.verticalLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 250, 21))
        self.menubar.setObjectName("menubar")
        self.menuFEA = QtWidgets.QMenu(self.menubar)
        self.menuFEA.setObjectName("menuFEA")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionExit = QtWidgets.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.menuFEA.addAction(self.actionExit)
        self.menubar.addAction(self.menuFEA.menuAction())
        self.setupPush.clicked.connect(self.code)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "FEA - Bar 2D"))
        MainWindow.setStatusTip(_translate("MainWindow", "Ready"))
        self.setupPush.setStatusTip(_translate("MainWindow", "Setup"))
        self.setupPush.setText(_translate("MainWindow", "Setup"))
        self.nodePropPush.setStatusTip(_translate("MainWindow", "Input node properties"))
        self.nodePropPush.setText(_translate("MainWindow", "Node Properties"))
        self.elPropLabel.setStatusTip(_translate("MainWindow", "Input element properties"))
        self.elPropLabel.setText(_translate("MainWindow", "Element Properties"))
        self.bcPush.setStatusTip(_translate("MainWindow", "Input boundary conditions"))
        self.bcPush.setText(_translate("MainWindow", "Boundary Conditons"))
        self.solvePush.setStatusTip(_translate("MainWindow", "Solve"))
        self.solvePush.setText(_translate("MainWindow", "Solve"))
        self.resultPush.setStatusTip(_translate("MainWindow", "List solution results"))
        self.resultPush.setText(_translate("MainWindow", "List Results"))
        self.menuFEA.setTitle(_translate("MainWindow", "FEA"))
        self.actionExit.setText(_translate("MainWindow", "Exit"))
        self.actionExit.setStatusTip(_translate("MainWindow", "Exit"))
        self.actionExit.setShortcut(_translate("MainWindow", "Ctrl+Q"))

    def code(self):
        print('Finally, I work! :)')

Below is the gui I would like to call with my setup pushbutton name above as setupPush

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_SetUp(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(300, 190)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(300, 190))
        MainWindow.setMaximumSize(QtCore.QSize(300, 190))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.formLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.formLayoutWidget.setGeometry(QtCore.QRect(20, 10, 261, 101))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(5, 10, 5, 5)
        self.formLayout.setSpacing(10)
        self.formLayout.setObjectName("formLayout")
        self.nnodeLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.nnodeLabel.setObjectName("nnodeLabel")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.nnodeLabel)
        self.nelLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.nelLabel.setObjectName("nelLabel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.nelLabel)
        self.ndofLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.ndofLabel.setObjectName("ndofLabel")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.ndofLabel)
        self.ndof = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.ndof.setObjectName("ndof")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.ndof)
        self.nel = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.nel.setObjectName("nel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.nel)
        self.nnode = QtWidgets.QLineEdit(self.formLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.nnode.sizePolicy().hasHeightForWidth())
        self.nnode.setSizePolicy(sizePolicy)
        self.nnode.setObjectName("nnode")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.nnode)
        self.ndof.raise_()
        self.nnodeLabel.raise_()
        self.nelLabel.raise_()
        self.nel.raise_()
        self.nnode.raise_()
        self.ndofLabel.raise_()
        self.mainOkPush = QtWidgets.QPushButton(self.centralwidget)
        self.mainOkPush.setGeometry(QtCore.QRect(20, 120, 75, 23))
        self.mainOkPush.setToolTip("")
        self.mainOkPush.setObjectName("mainOkPush")
        self.mainCancelPush = QtWidgets.QPushButton(self.centralwidget)
        self.mainCancelPush.setGeometry(QtCore.QRect(210, 120, 75, 23))
        self.mainCancelPush.setObjectName("mainCancelPush")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 300, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Main Window"))
        self.nnodeLabel.setText(_translate("MainWindow", "Number of Nodes"))
        self.nelLabel.setText(_translate("MainWindow", "Number of Elements"))
        self.ndofLabel.setText(_translate("MainWindow", "Number of DOF per node"))
        self.mainOkPush.setStatusTip(_translate("MainWindow", "Save and continue"))
        self.mainOkPush.setText(_translate("MainWindow", "OK"))
        self.mainCancelPush.setStatusTip(_translate("MainWindow", "Cancel"))
        self.mainCancelPush.setText(_translate("MainWindow", "Cancel"))

Body:
The signal connection must be given in the Primary class or a class that inherits from QObject. Also the way you use Ui_primary and its methods is incorrect. Finally you must create a class that can use your design, this is called SetUp, and then we connect the show function to the button (I used the button nodePropPush).

class SetUp(QtWidgets.QMainWindow, Ui_SetUp):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)

class Primary(QtWidgets.QMainWindow, Ui_Primary):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.setupPush.clicked.connect(self.code)

        s = SetUp(self)

        self.nodePropPush.clicked.connect(s.show)

    def code(self):
        print('Finally, I work! :)')

complete code:

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_SetUp(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(300, 190)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(300, 190))
        MainWindow.setMaximumSize(QtCore.QSize(300, 190))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.formLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.formLayoutWidget.setGeometry(QtCore.QRect(20, 10, 261, 101))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(5, 10, 5, 5)
        self.formLayout.setSpacing(10)
        self.formLayout.setObjectName("formLayout")
        self.nnodeLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.nnodeLabel.setObjectName("nnodeLabel")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.nnodeLabel)
        self.nelLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.nelLabel.setObjectName("nelLabel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.nelLabel)
        self.ndofLabel = QtWidgets.QLabel(self.formLayoutWidget)
        self.ndofLabel.setObjectName("ndofLabel")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.ndofLabel)
        self.ndof = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.ndof.setObjectName("ndof")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.ndof)
        self.nel = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.nel.setObjectName("nel")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.nel)
        self.nnode = QtWidgets.QLineEdit(self.formLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.nnode.sizePolicy().hasHeightForWidth())
        self.nnode.setSizePolicy(sizePolicy)
        self.nnode.setObjectName("nnode")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.nnode)
        self.ndof.raise_()
        self.nnodeLabel.raise_()
        self.nelLabel.raise_()
        self.nel.raise_()
        self.nnode.raise_()
        self.ndofLabel.raise_()
        self.mainOkPush = QtWidgets.QPushButton(self.centralwidget)
        self.mainOkPush.setGeometry(QtCore.QRect(20, 120, 75, 23))
        self.mainOkPush.setToolTip("")
        self.mainOkPush.setObjectName("mainOkPush")
        self.mainCancelPush = QtWidgets.QPushButton(self.centralwidget)
        self.mainCancelPush.setGeometry(QtCore.QRect(210, 120, 75, 23))
        self.mainCancelPush.setObjectName("mainCancelPush")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 300, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Main Window"))
        self.nnodeLabel.setText(_translate("MainWindow", "Number of Nodes"))
        self.nelLabel.setText(_translate("MainWindow", "Number of Elements"))
        self.ndofLabel.setText(_translate("MainWindow", "Number of DOF per node"))
        self.mainOkPush.setStatusTip(_translate("MainWindow", "Save and continue"))
        self.mainOkPush.setText(_translate("MainWindow", "OK"))
        self.mainCancelPush.setStatusTip(_translate("MainWindow", "Cancel"))
        self.mainCancelPush.setText(_translate("MainWindow", "Cancel"))

class Ui_Primary(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(250, 300)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(250, 300))
        MainWindow.setMaximumSize(QtCore.QSize(250, 300))
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setContentsMargins(5, 10, 5, 5)
        self.verticalLayout.setSpacing(10)
        self.verticalLayout.setObjectName("verticalLayout")
        self.setupPush = QtWidgets.QPushButton(self.centralwidget)
        self.setupPush.setObjectName("setupPush")
        self.verticalLayout.addWidget(self.setupPush)
        self.line_5 = QtWidgets.QFrame(self.centralwidget)
        self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_5.setObjectName("line_5")
        self.verticalLayout.addWidget(self.line_5)
        self.nodePropPush = QtWidgets.QPushButton(self.centralwidget)
        self.nodePropPush.setObjectName("nodePropPush")
        self.verticalLayout.addWidget(self.nodePropPush)
        self.line_4 = QtWidgets.QFrame(self.centralwidget)
        self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.verticalLayout.addWidget(self.line_4)
        self.elPropLabel = QtWidgets.QPushButton(self.centralwidget)
        self.elPropLabel.setObjectName("elPropLabel")
        self.verticalLayout.addWidget(self.elPropLabel)
        self.line_3 = QtWidgets.QFrame(self.centralwidget)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.verticalLayout.addWidget(self.line_3)
        self.bcPush = QtWidgets.QPushButton(self.centralwidget)
        self.bcPush.setObjectName("bcPush")
        self.verticalLayout.addWidget(self.bcPush)
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.verticalLayout.addWidget(self.line_2)
        self.solvePush = QtWidgets.QPushButton(self.centralwidget)
        self.solvePush.setObjectName("solvePush")
        self.verticalLayout.addWidget(self.solvePush)
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.verticalLayout.addWidget(self.line)
        self.resultPush = QtWidgets.QPushButton(self.centralwidget)
        self.resultPush.setObjectName("resultPush")
        self.verticalLayout.addWidget(self.resultPush)
        self.verticalLayout_2.addLayout(self.verticalLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 250, 21))
        self.menubar.setObjectName("menubar")
        self.menuFEA = QtWidgets.QMenu(self.menubar)
        self.menuFEA.setObjectName("menuFEA")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionExit = QtWidgets.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.menuFEA.addAction(self.actionExit)
        self.menubar.addAction(self.menuFEA.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "FEA - Bar 2D"))
        MainWindow.setStatusTip(_translate("MainWindow", "Ready"))
        self.setupPush.setStatusTip(_translate("MainWindow", "Setup"))
        self.setupPush.setText(_translate("MainWindow", "Setup"))
        self.nodePropPush.setStatusTip(_translate("MainWindow", "Input node properties"))
        self.nodePropPush.setText(_translate("MainWindow", "Node Properties"))
        self.elPropLabel.setStatusTip(_translate("MainWindow", "Input element properties"))
        self.elPropLabel.setText(_translate("MainWindow", "Element Properties"))
        self.bcPush.setStatusTip(_translate("MainWindow", "Input boundary conditions"))
        self.bcPush.setText(_translate("MainWindow", "Boundary Conditons"))
        self.solvePush.setStatusTip(_translate("MainWindow", "Solve"))
        self.solvePush.setText(_translate("MainWindow", "Solve"))
        self.resultPush.setStatusTip(_translate("MainWindow", "List solution results"))
        self.resultPush.setText(_translate("MainWindow", "List Results"))
        self.menuFEA.setTitle(_translate("MainWindow", "FEA"))
        self.actionExit.setText(_translate("MainWindow", "Exit"))
        self.actionExit.setStatusTip(_translate("MainWindow", "Exit"))
        self.actionExit.setShortcut(_translate("MainWindow", "Ctrl+Q"))

import sys

class SetUp(QtWidgets.QMainWindow, Ui_SetUp):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)

class Primary(QtWidgets.QMainWindow, Ui_Primary):
    def __init__(self, parent = None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.setupPush.clicked.connect(self.code)

        s = SetUp(self)

        self.nodePropPush.clicked.connect(s.show)

    def code(self):
        print('Finally, I work! :)')

if __name__== '__main__':
    app = QtWidgets.QApplication(sys.argv)
    myapp = Primary()
    myapp.show()
    app.aboutToQuit.connect(app.deleteLater)
    app.exec_()


问:
Publish simple Asp.Net Core App (.Net Framework) with WebJob
I would like to create a simple ASP.NET Core Web Application (.NET Framework) and publish a WebJob alongside it to Azure.

I'm using Visual Studio 2017, but the result seems to be the same in VS2015.

To start, I create the corresponding project in VS2017:

I select the basic web application template:

At this point I get a bit lost. In the older Asp.Net MVC 5 approach, I used to be able to click on the Asp.Net project and find "Add => New Azure Webjobs Project". The WebJob would then always be linked in publishing and just "work".

With the new Asp.Net Core approach, I can't seem to find an analogously-easy way to get this happening.

I tried manually adding a WebJobs project to the solution and then manually setting up the webjobs-list.json file in the Asp.Net project, but the publish step didn't recognize it. I noticed various answers like this one which suggest hooking into the publishing process to copy the files, but the markup added to the *.pubxml file didn't have any affect (i.e. the files weren't being copied).

It seems that there's a bit of outdated information around regarding this task. Might somebody be able to detail the current process of doing this for a new solution containing an Asp.Net Core app in Visual Studio?

答:
You can use this lines for VSTS builds VS2017 csproj</p>

```<code><Target Name="PostpublishScript" AfterTargets="Publish">
    <Exec Command="dotnet publish ..\SampleWebJob\ -o $(PublishDir)App_Data\Jobs\Continuous\SampleWebJob" />
  </Target>
</code>```

Body:
You can use this lines for VSTS builds VS2017 csproj

<Target Name="PostpublishScript" AfterTargets="Publish">
    <Exec Command="dotnet publish ..\SampleWebJob\ -o $(PublishDir)App_Data\Jobs\Continuous\SampleWebJob" />
  </Target>


问:
Best Way to Refresh Adapter/ListView on Android
My book, "Hello Android" gives this as a way of using a custom db helper, setting up a cursor, and then setting up an adapter as follows:

```<code>Cursor cursor
CustomDatabaseHelper test = new CustomDatabaseHelper(this);
try {
        cursor = getData();
        showData(cursor);
} finally {
        test.close();
}
</code>```

With this however, everytime I need to refresh the data set, I need to keep running this block of code (which gets a bit difficult inside an onClick() for a button due to "this" not being available.

Is this the best way to refresh the data set, or should I look towards removing the .close and issue an adapter.notifyDataSetChanged()? If I do this, sometimes I get a force close as (and I can't remember at the moment) but sometimes it cannot Delete properly - I think this may be because the database is currently open and it tries to open again.

Should we also be declaring the variables for the Cursors, DatabaseHelpers and Adapter in the Class (outside of the OnCreate) so that they are accessible to all the functions?

I realise this is just poor programming at this stage, but Im trying to get some pointers as to the best way of doing things.

答:
Best Way to Refresh Adapter/ListView on Android

Not only calling notifyDataSetChanged() will refresh the ListView data, setAdapter() must be called before to load the information correctly:

```<code>  listView.setAdapter(adapter);
  adapter.notifyDataSetChanged();
</code>```

ContentLicense: CC BY-SA 2.5

Body:
My book, "Hello Android" gives this as a way of using a custom db helper, setting up a cursor, and then setting up an adapter as follows:

Cursor cursor
CustomDatabaseHelper test = new CustomDatabaseHelper(this);
try {
        cursor = getData();
        showData(cursor);
} finally {
        test.close();
}

With this however, everytime I need to refresh the data set, I need to keep running this block of code (which gets a bit difficult inside an onClick() for a button due to "this" not being available.

Is this the best way to refresh the data set, or should I look towards removing the .close and issue an adapter.notifyDataSetChanged()? If I do this, sometimes I get a force close as (and I can't remember at the moment) but sometimes it cannot Delete properly - I think this may be because the database is currently open and it tries to open again.

Should we also be declaring the variables for the Cursors, DatabaseHelpers and Adapter in the Class (outside of the OnCreate) so that they are accessible to all the functions?

I realise this is just poor programming at this stage, but Im trying to get some pointers as to the best way of doing things.

Body:
Best Way to Refresh Adapter/ListView on Android

Not only calling notifyDataSetChanged() will refresh the ListView data, setAdapter() must be called before to load the information correctly:

  listView.setAdapter(adapter);
  adapter.notifyDataSetChanged();