I get error on      java.lang.NullPointerException: Attempt to invoke interface method   'java.sql.Statement java.sql.Connection.createStatement()' on a null   object reference at   com.example.jacquesarroyo.onlinelibrary.suggestions$3.onClick(suggestions.java:81)   Here's the code I used:  add = (Button) findViewById(R.id.btnadd); errorlbl = (TextView) findViewById(R.id.lblerror); title = (EditText) findViewById(R.id.txttitle); author = (EditText) findViewById(R.id.txtauthor); year = (EditText) findViewById(R.id.txtyear); location = (EditText) findViewById(R.id.txtlocation);  ipaddress = "10.0.0.5";    db = "SampleDatabase";  username = "admin" password = "admin"; connect = ConnectionHelper(username, password, db, ipaddress);  add.setOnClickListener(new View.OnClickListener() {         @Override         public void onClick(View v) {             try {                 st = connect.createStatement();                 preparedStatement = connect                         .prepareStatement("Insert into Books(Title,Author,Year) values ('"                                 + title.getText().toString()                                 + "','"                                 + author.getText().toString()                                 + "','"                                 + year.getText().toString() + "')");                 preparedStatement.executeUpdate();                 errorlbl.setText("Data Added successfully");             } catch (SQLException e) {                 errorlbl.setText(e.getMessage().toString());             }         }     });  @SuppressLint("NewApi") private Connection ConnectionHelper(String user, String password,                                     String database, String server) {     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()             .permitAll().build();     StrictMode.setThreadPolicy(policy);     Connection connection = null;     String ConnectionURL = null;     try {         Class.forName("net.sourceforge.jtds.jdbc.Driver");         ConnectionURL = "jdbc:jtds:sqlserver://" + server + ";"                 + "databaseName=" + database + ";user=" + user                 + ";password=" + password + ";" + "ssl=false";         connection = DriverManager.getConnection(ConnectionURL);       } catch (SQLException se) {         Log.e("ERROR", se.getMessage());     } catch (ClassNotFoundException e) {         Log.e("ERROR", e.getMessage());     } catch (Exception e) {         Log.e("ERROR", e.getMessage());     }     return connection; }   line 81 is: st = connect.createStatement();
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
Which are the safety recommendations for soldering? Difference of Gamma random variables Is there any way to keep a command from being added to your history? I have a command that I want to keep out of my history file, and I really don't care to have it there when I search the history stored in memory, though that's less of a concern. Is there any way to prevent this, or do I just have to go back and edit my history file.  update: I didn't realize this might be shell-specific. My shell is zsh. You're welcome to answer for other shells so people know how to do this in their shell. How to get the last argument to a /bin/sh function What's a better way to implement print_last_arg?  #!/bin/sh  print_last_arg () {     eval "echo \${$#}"  # this hurts }  print_last_arg foo bar baz # baz   (If this were, say, #!/usr/bin/zsh instead of #!/bin/sh I'd know what to do.  My problem is finding a reasonable way to implement this for #!/bin/sh.)  EDIT: The above is only a silly example.  My goal is not to print the last argument, but rather to have a way to refer to the last argument within a shell function.    EDIT2: I apologize for such an unclearly worded question.  I hope to get it right this time.  If this were /bin/zsh instead of /bin/sh, I could write something like this  #!/bin/zsh  print_last_arg () {     local last_arg=$argv[$#]     echo $last_arg }   The expression $argv[$#] is an example of what I described in my first EDIT as a way to refer to the last argument within a shell function.  Therefore, I really should have written my original example like this:  print_last_arg () {     local last_arg=$(eval "echo \${$#}")   # but this hurts even more     echo $last_arg }   ...to make it clear that what I'm after is a less awful thing to put to the right of the assignment.  Note, however, that in all the examples, the last argument is accessed non-destructively.  IOW, the accessing of the last argument leaves the positional arguments as a whole unaffected. I've seen them maneuver. They definitely can go backwards. How fast can they go in reverse? Is warp speed possible, or is reverse limited to impulse power? If it is limited to impulse power, can they travel backwards under impulse power as fast as they travel forwards under impulse power? How to import Illustrator swatch libraries into InDesign - Adobe Indesign Mac? I have a very reach swatch library in adobe-illustrator like food colors and.... But in adobe-indesign I don't have many colors. Why? Can I import them to indesign? Where can I see how many posts have I edited? I read recently that you can find the number of digits in a number through the formula $\lfloor \log_{10} n \rfloor +1$ What's the logic behind this rather what's the proof? How can I respawn the Ender Dragon? I have a server and the Ender dragon has been defeated.  However, returning to The End does not respawn the Ender Dragon.  How can I get the final boss back on a vanilla server without using mods? I remember watching this sci-fi movie where a huge metallic capsule gets dropped from a few hundred meters. The capsule had a chamber inside where only one person could be seated. During the drop, time dilated and the person would transcend to another world, lasting for days, even meeting dead people. Kind of a parallel reality.  It was an amazing movie, but I cannot recall its name. No surname in my passport Proving : $ \bigl(1+\frac{1}{n+1}\bigr)^{n+1} \gt (1+\frac{1}{n})^{n} $ The coefficient of $x^9$ in the expansion of $(1+x)(1+x^2)(1+x^3)...(1+x^{100})$.  I tried the following concept, how to sum 9 using 1-9 only without repetition.  1:9, 2:1+8,3:7+2, 4: 6+3, 5: 5+4,  6:1+2+6 ,7:1+3+5, 8:2+3+4  The answer is 8.  How will it be solved using Binomial theorem. I have a small question regarding using sudo with output redirect &gt;. To enable IP forwrding, someone can use the command:  echo 1 &gt; /proc/sys/net/ipv4/ip_forward   Executing this command will give permission denied as it requires root privileges. However, executing the same command with sudo gives also permission denied error! It seems that output redirect &gt; does not inherit the permissions of the preceding command echo. Is this right?  As a workaround I do:  echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward   Is this the best way to do it? Am I missing something?  Please, note that this is an example and it applies to all commands that use output redirect. If a topology contains all infinite subsets, then it is the discrete topology I am solving question $8$ of exercises in section 1.1. of chapter 1 in "Topology without tears". The question reads as follows.     Let $X$ be an infinite set and $\tau$ be a topology on $X$. If every infinite subset of $X$ is in $\tau$, prove that $\tau$ is the discrete topology   My idea was to show that every singleton set is in the topology and thereby the topology is discrete.  Choose an infinite set $A$ from $X$ such that $A^c$ is also infinite. $A$ and $A^c$ belong to $\tau$ since they are infinite sets. Now consider any $x \in X$. Note that $A \cup \{x\}$ and $A^c \cup \{x\}$ belong to $\tau$ since they are infinite sets. Hence, their intersection which is nothing but $\{x\} \in \tau$ for every $x \in X$.  The problem I have is I don't know how to prove the first sentence in the previous paragraph. These are my line of thoughts to prove them.   If $X$ is a countably infinite set, then I can list the elements are let the odd numbered elements fall into $A$. This guarantees $A$ and $A^c$ are both infinite. If $X$ is uncountable, then I can choose a countably infinite subset and call it $A$.   Are the above arguments rigorous? I am not especially happy with my second argument of choosing a countably infinite subset from an uncountable set since I do not give an explicit procedure of constructing the set $A$.  Also, is there any other simpler way of answering the original question? Finding the left and right cosets of H = {(1), (12), (34), (12) ○ (34)} in S4 I have an exercise where I am supposed to find the left and right cosets of H = {(1), (12), (34), (12) ○ (34)} in S4. But how do I generate the cosets? As I have understood it you are supposed to pick a number that is not in the set H and multiply it with every number in H. But this does not exactly give the right answer. I would really appreciate it if someone gave an easy to understand explanation of how to generate the left and right cosets. A short story about finding an inhabitable planet and meeting aliens How to run a command when a directory's contents are updated? There is a directory A whose contents are changed frequently by other people.  I have made a personal directory B where I keep all the files that have ever been in A.  Currently, I just occasionally run rsync to get the files to be backed up from A to B. However, I fear the possibility that some files will get added in A, and then removed from A before I get the chance to copy them over to B.  What is the best way to prevent this from occurring? Ideally, I'd like to have my current backup script run every time the contents of A get changed. build argument lists containing whitespace In bash one can escape arguments that contain whitespace.  foo "a string"   This also works for arguments to a command or function:  bar() {     foo "$@" }  bar "a string"   So far so good, but what if I want to manipulate the arguments before calling foo?  This does not work:  bar() {     for arg in "$@"     do         args="$args \"prefix $arg\""     done      # Everything looks good ...     echo $args      # ... but it isn't.     foo $args      # foo "$args" would just be silly }  bar a b c   So how do you build argument lists when the arguments contain whitespace? How to represent it with UNIQUE indexes and foreign keys?