Mock to HTTP connection gives null pointer exception I am trying to mock HTTP method I created. For the get method, the test fail when trying to do POST\PUT, I am getting null exception.   I will put part of my code:  public HTTPResult httpPostPutGetRequest(String url, String jsonString, String requestMethod) throws Exception {     HttpURLConnection connection = connectionFactory.createURLConnection(url);     connection.setRequestMethod(requestMethod);     String result = null;     if (requestMethod == "PUT" || requestMethod == "POST") {          connection.setDoOutput(true);         connection.setRequestProperty("Content-Type", "application/json");         connection.setRequestProperty("Accept", "application/json");          OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream());         osw.write(String.format(jsonString));         osw.close();   Then I am trying to mock it by the following:  public class StepdefsCommonTest {      private static final int PORT = 51234;     private static final String baseUrl = "http://localhost:" + PORT;     private HTTPResult result = null;      private String responseBody = "{blbl}";     private String responseMessage = "OK";     private int responseCode = 200;      public HTTPResult mockHttpRequest(String httpMethod) throws Exception {          HttpURLConnection mockHttpURLConnection = mock(HttpURLConnection.class);         URLConnectionFactory mockURLConnectionFactory = mock(URLConnectionFactory.class);          ByteArrayInputStream responseBodyInputStream = new ByteArrayInputStream(responseBody.getBytes());         when(mockHttpURLConnection.getResponseCode()).thenReturn(responseCode);         when(mockHttpURLConnection.getResponseMessage()).thenReturn(responseMessage);         when(mockHttpURLConnection.getInputStream()).thenReturn(responseBodyInputStream);         when(mockURLConnectionFactory.createURLConnection(baseUrl)).thenReturn(mockHttpURLConnection);          StepdefsCommon common = new StepdefsCommon(mockURLConnectionFactory);          HTTPResult res = null;          switch(httpMethod){             case "POST":case "PUT":                 try {                     res = common.httpPostPutGetRequest(baseUrl,responseBody,httpMethod);                 } catch (IOException e) {                     e.printStackTrace();                 }   I am getting null pointer exception for:  OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream()); The exception I am getting:  java.lang.NullPointerException     at java.io.Writer.&lt;init&gt;(Writer.java:88)     at java.io.OutputStreamWriter.&lt;init&gt;(OutputStreamWriter.java:109)
What is a NullPointerException, and how do I fix it? 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?
How to find $\operatorname{Gal}(S/\mathbb{Q})$ Noun order: "He and we..." or "We and he..."? Similarly, "...him and us" or "...us and him"? It's convention and polite to always list yourself last in a list. I say "John and I went to the store" and not "I and John went to the store."  So does that mean that I should always list myself last, even in the case when the pronoun that represents me is first person, plural (i.e. "us" or "we")? In my case, I'm writing a recommendation letter about my experience on a team with "John," who is the highlight of the letter. I hit a point where I was about to write something similar to:     John and we got a lot of experience working on the project.   or     That project's experience really benefited John and us.   Clearly, he is mentally separated from the others of us who were on the team, at least in this context, so I was just wondering if there were some grammatical conventions to govern this situation. I just read on wikipedia that the the complex projective line is homeomorphic to the riemann sphere. How do I prove this? But, before that I have an extremely silly doubt that has been eating me. In the complex projective line, antipodal points are identified, but in the Riemann sphere they are clearly distinct. Then how can the two be homeomorphic.   I found out the following map from the complex projective line to $S^2$. But how do I prove this is a homeomorphism? Finding the inverse of this functions seems complicated, and then how do I prove that the inverse map of a open subset is a open subset, and vice versa?  $f:\mathbb{C}\mathbb{P}^1 \to S^2 = [z:w] \to \frac{(2Re(w\bar{z}), 2Im(w\bar{z}),|w|^2-|z|^2)}{(|w|^2+|z|^2)} $ Printing a file to a printer in Ruby Zero morphism does not depend on zero object I want to prove that zero morphism does not depend on zero object. Let a zero object $0 \in \mathcal{C}$.  I supposed that exists another zero object $0' \in \mathcal{C}$, and I considered $0: A \to B$ and also $$A \to 0 \to 0' \to B$$ But I don't know to prove that zero morphism $0: A \to B$ not does not depend on zero object. Can anybody give me a suggestion? As seen in this video: (Skip to 5:53)  When a player is slain, they drop an Enchanting Table on top of their inventory.  How was this achieved and how can I build a system (using command blocks) that does that? Come to think of it, what happens to a player's location when he/she dies? Does it reset to the spawnpoint? Stay the same (where they died) until they respawn? Or becomes a null value until they respawn? Usually a probability distribution over discrete variables is described using a probability mass function (PMF):  When working with continuous random variables, we describe probability distributions using a probability density function (PDF) rather than a probability mass function. -- Deep Learning by Goodfellow, Bengio,  and Courville  However,  is using PDF to describe the probability distribution over discrete variables:    Is this a mistake? or it does not much matter? Between you and ("me" or "I")? Is it correct to say "between you and me" or "between you and I"?  I am not a native English speaker, so please bear with me. Is  structured data (in Microdata, JSON-LD, or RDFa) relevant for SEO?   I know that structured data can provide benefits in other areas, but here I’m only asking about its significance for general web search engines. we have been using the Find Nearby Accounts app from appexchange for a while now. The app uses the Google Maps API vs 2 which is now deprecated and hence has rendered the app ineffective. I have tried migrating the Google maps API version for the app from v2 to v3 by generating a v3 API key. The URL for my salesforce instance was included in the creation of the Client ID under API Access. After all these steps, I still get the error "Problem with Address. I know the address is right.   Has anyone been able to get this working? Thanks. I have three different 1024-bit public keys with common exponent $e$ but different moduli. A message $m$ is encrypted (without padding) using the three keys, which results in three different encrypted messages.  Given the three pairs of public keys $(N_i,e)$ and the encrypted messages $c_i=m^e\bmod N_i$ , how do I decipher the original message $m$ ? Is there a CSS selector for elements containing certain text? How do tag merge requests work? I had raised a  to merge pre-build-event, and pre-buildevent; and postbuild-event and post-build-event. That was about 11 months ago, and I still see these two tags even now.  How are tag merge requests handled? Is there a better way for tag merge requests other than posting on Meta? How do I recursively create a folder inside another non-existent folder? I want to create this folder: $HOME/a/b/c/d while $HOME/a has not yet been created! Is it possible with one line in Terminal? Is there a way in Adobe Creative Suite to "share palettes/swatches" across programs? I use a mixture of InDesign, Photoshop and Illustrator to produce the vast amount of printed media I design at my current position and I find myself faced with copy/pasting color values from one program to another almost all the time, I have tried to find a quicker way but have been unsuccessful. I use a program called  to copy and store my most used colors, but still, it's not the same as being able to select it from the swatches palette in Adobe CS.  So the main meat of the question is:   Can I share my colors/swatches between InDesign, Photoshop and Illustrator and if so, how? Show that $\langle 2,x \rangle$ is not a principal ideal in $\mathbb Z [x]$ Proving that two vector spaces of equal dimension are isomorphic Given the following problem     Let $U$ and $V$ be finite dimensional vector spaces, such that $\dim(U) = \dim(V)$. Prove that $U$ and $V$ are isomorphic.   I was just wondering if somebody could critique and validate my proof.  Proof  Two vector spaces $U$ and $V$ are isomorphic if and only if there exists a bijection $\phi: U \to V$. That is, an invertible linear map between the two. Let $\dim(U) = \dim(V) = n$ and let $\left\{u_1, \dots, u_n\right\}$ and $\left\{v_1, \dots, v_n\right\}$ be bases for $U$ and $V$, respectively. It follows that any vector $u \in U$ can be written as  $$ u = c_1u_1 + \cdots + c_nu_n $$  We define $\phi: U \to V$ as  $$ \phi(c_1u_1 + \cdots + c_nu_n) = c_1v_1 + \cdots + c_nv_n $$  Observe that $\phi$ is invertible. That is, given a vector  $$ v = d_1v_1 + \cdots + d_nv_n $$  in $V$, we define $\phi^{-1}: V \to U$ as  $$ \phi^{-1}(d_1v_1 + \cdots + d_nv_n) = d_1u_1 + \cdots + d_nu_n $$  Since there exists a bijection between $U$ and $V$, they are isomorphic. How do I remove Windows but keep Ubuntu? Performance differences between equal (=) and IN with one literal value MySQL Error 1093 - Can't specify target table for update in FROM clause