HashMap.containsKey(s.charAt(i)) evaluates to true but map.get(s.charAt(i)) results in Null Pointer Exception? given two strings s and t, I am trying to find the minimum number of steps to make s an anagram of t. For some reason, I get a null pointer exception when trying to get a key from a map, even after I have verified in the if statement that the map does indeed contain the key. Why is this happening? class Solution {     public int minSteps(String s, String t) {         HashMap&lt;Character, Integer&gt; map = new HashMap&lt;&gt;();         for (int i = 0; i &lt; t.length(); i++) {             if (map.containsKey(t.charAt(i))) {                 map.put(t.charAt(i), map.get(t.charAt(i) + 1));             } else {                 map.put(t.charAt(i), 1);             }         }         int steps = 0;         for (int i = 0; i &lt; s.length(); i++) {             if (map.containsKey(s.charAt(i))) {                 int q = map.get(s.charAt(i)); //results in null pointer exception                 if (q &lt; 1) {                     steps++;                 } else {                     map.put(s.charAt(i), q-1);                 }             } else {                 steps++;             }         }         return steps;     } }
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?
In the LoTR movies (not sure if the books are the same) but when Gollum lost the ring to Bilbo decades ago in The Hobbit, he appeared to look the same and even move the same in The Fellowship of the Ring. Bilbo on the other hand, seemed to have aged very rapidly when he passed the ring to Frodo. When Frodo met up with Bilbo in Rivendell shortly after his quest began, Bilbo appeared much older and even more much slower.  I realize that Gollum had the ring for much longer than Bilbo, but wouldn't him losing the ring have the same effect as it had on Bilbo? Space before chapters and contents I am using LaTeX to write my dissertation, and I have realised that on the table of contents and on every chapter page, LaTeX leaves a lot of empty space.  What I mean is that lets say in the page where chapter 1 begins, from the top of the page until the chapter title there is much more vertical space than on any other page. The same goes with chapter 2 etc... and for contents page as well.   Can anybody help me to remove that space? Is there any mistake in my code or something like that? Is this a default of LaTeX?  the preamble is  \documentclass[12pt,twoside]{report} \pagestyle{plain} \usepackage{a4paper} \usepackage{setspace} \doublespacing  \usepackage{amssymb} \usepackage{amsmath}    I've tried the methods below, but none of them work properly. Is there a picture showing all the lengths used in lists? Using proof by contradiction vs proof of the contrapositive What is the difference between a "proof by contradiction" and "proving the contrapositive"? Intuitive, it feels like doing the exact same thing. And when I compare an exercise, one person proves by contradiction, and the other proves the contrapositive, the proofs look almost exactly the same.  For example, say I want to prove: $P \implies Q$ When I want to prove by contradiction, I would say assume this is not true. Assume $Q$ is not true, and $P$ is true. Blabla, but this implies $P$ is not true, which is a contradiction.  When I want to prove the contrapositive, I say. Assume $Q$ is not true. Blabla, this implies $P$ is not true.  The only difference in the proof is that I assume $P$ is true in the beginning, when I want to prove by contradiction. But this feels almost redundant, as in the end I always get that this is not true. The only other way that I could get a contradiction is by proving that $Q$ is true. But this would be the exact same things as a direct proof.   Can somebody enlighten me a little bit here ? For example: Are there proofs that can be proven by contradiction but not proven by proving the contrapositve? Get selected text from a drop-down list (select box) using jQuery How do you do it? Given a byte array:  byte[] foo = new byte[4096];   How would I get the first x bytes of the array as a separate array? (Specifically, I need it as an IEnumerable&lt;byte&gt;)  This is for working with Sockets. I figure the easiest way would be array slicing, similar to Perls syntax:  @bar = @foo[0..40];   Which would return the first 41 elements into the @bar array. Is there something in C# that I'm just missing, or is there some other thing I should be doing?  LINQ is an option for me (.NET 3.5), if that helps any. How can I identify duplicate image files? Over the years, I've accumulated a lot of pictures, across a bunch of different machines.  I think I've mostly kept them in a yyyy/mm/ directory structure, but especially with some of the older pictures, there seem to be a lot of duplicates.  What's the best way to identify the duplicates?  Are there good tools to do this, or am I going to have to write something on my own? I've already installed Steam, but when I click on the program I get this message  ERROR- You are missing the following 32-bit libraries, and Steam may not run: not   I don't know what to install or even do. I need to solve $3x^2 + 6x +1 \equiv 0 \pmod {19}$  I saw the same problem here -     but didn't understand how he got to the conclusion   $x(x+2) \equiv 6 \pmod {19}$  and anyway im trying to solve it how we learned in class -   multiply both sides and the modulo by $4a$ then solve the two equations  $y^2 \equiv b^2 -4ac \pmod {4an}$  $2ax + b \equiv y \pmod {4an}$  so I tried multiplying the hole thing by $4a$ , that is $4 \times 3$  and got to $(2 \times 3x + 6)^2 \equiv 36 -4 \times 3 \pmod {19 \times 4 \times 3}$  now I am stuck . any help will be appreciated Integral of $\frac{1}{2x}$ How to Remove shortcut arrow from desktop icons? How do I turn off the arrow for desktop icons? "a ten years old boy" or "a ten year old boy" UK coastline shapefile? Why are springs shaped the way they are? Why are springs coiled the way they are? Why not some other shape? Is the shape due to its elasticity or something? Editable fields in views Reputation changes not visible in the achievement box (again) Just like , which was marked as . But today, it's not working again. I'm still notified of new badges:      Update: it looks like new events are now updated; reputation events from earlier this UTC afternoon are still missing: I need some help importing MrSID Raster files in QGIS. I am running 2.6.0 on Linux Mint 17. After an internet search I have found a couple of resources that are perhaps outdated. The most promising is found here :    However when I attempted to follow the instructions my terminal and I could not find the file "libgdal-mrsid-src" on either the stable or unstable Ubuntu GIS repos. Has anyone had success or could lead me in the right direction? Usually in the morning I brush my teeth after breakfast. But my dentist told me that it's better not brush them right after eating food, because eating makes them soft.  So now I brush my teeth before breakfast. Is this the correct procedure?  PS. Just found , the author has the same opinion.  Just want to get a additional confirmation. got me wondering about the differences between these three ways of measuring size: a kibibyte, a kilobit, and the conventional kilobyte.  I understand that these measurements have different uses (data transfer rate is measured in bits/sec), but I'm not quite sure if I can tell the difference between Mb and MB and MiB.  Here is a comment, reproduced below, taken from  (emphasis mine).     The C64 has 65536 bytes of RAM. By   convention, memory size is specified   in kibiBytes, data transfer rates in   kilobits, and mass storage in   whatever-the-manufacturers-think-of-now-Bytes. Harddrives use T, G, M and k on the   label, Windows reports the size in Ti,   Gi, Mi and ki. And those 1.44MB   floppys? Those are neither 1.44MB nor   1.44MiB, they are 1.44 kilokibibytes. That's 1440kiB or 1'474'560 bytes. –   Third Virtualbox not seeing any usb devices in the usb filters settings I was following this question but found a problem.   I used guvcview to test the camera, it works. I installed the 12.04 virtualbox release from their website and installed the extension pack. But when I click the usb with the green plus sign it says no devices available.