I have written the following code to solve the Longest SubStrings With All Unique Characters.  How can I fix this issue? , I understand what a null pointer exception is and why am I getting it , the question is what changes could be done such that I get the result  based on the question. Again , what could be changed logically in this particular piece of code to make it work as its intended , receiving a null pointer exception public class LongestSubStringWithAllUniqueChars {   static Map findUnique(char[] arr , int l , int r){     Map&lt;Character,Integer&gt; map = new HashMap();     for(int i=l;i&lt;r;i++){         if(map.containsKey(arr[l])){             map.put(arr[l],map.get(arr[l])+1);         }else{             map.put(arr[l],1);         }     }     map.forEach((c,v) -&gt;{         System.out.println(c+&quot; &quot;+v);     });     return map; } public static void main(String[] args) {     String str = &quot;GEEKSFORGEEKS&quot;;     char[] arr = str.toCharArray();     int l = 0;int r=0;     int max =0;     Map map  = new HashMap&lt;&gt;();       while(r&lt;arr.length){         r++;         map = findUnique(arr,l,r);         if(map.size() &lt; r-l+1){             r++;             map.put(arr[l],(int)map.get(arr[l])-1);             while(map.size()&lt; r-l+1){                 map.remove(arr[l],(int)map.get(arr[l])); // getting nullpointer here                 l++;             }          } else if(map.size()==r-l+1){             max = r-l+1;             r++;         }     }     System.out.println(max);  }  }
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?
jQuery .ready in a dynamically inserted iframe We are using jQuery  to dynamically display an iframe when someone clicks on a picture.  In this iframe, we are using  a javascript library to display multiple pictures.  The problem seems to be that $(document).ready in the iframe seems to be fired too soon and the iframe content isn't even loaded yet, so galleria code is not applied properly on the DOM elements.  $(document).ready seems to use the iframe parent ready state to decide if the iframe is ready.  If we extract the function called by document ready in a separate function and call it after a timeout of 100&nbsp;ms. It works, but we can't take the chance in production with a slow computer.  $(document).ready(function() { setTimeout(ApplyGalleria, 100); });   My question: which jQuery event should we bind to to be able to execute our code when the dynamic iframe is ready and not just it's a parent? Rayleigh-Jeans Law My question is simple, why do we believe  to be absurd? Is the Ultra-violet catastrophe incorrect or is it only because we can not create or know of a perfect emitter? I am a bit confused as to why Quanta was necessary. Where, in the Windows 7 file system, are the taskbar shortcuts stored (per user)? Does a filament of lamp still have resistance when no current flows, and if yes, why? Does a filament lamp still have resistance when no current flows? What is the best way(s) to fake function overloading in Javascript?   I know it is not possible to overload functions in Javascript as in other languages.  If I needed a function with two uses foo(x) and foo(x,y,z) which is the best / preferred way:   Using different names in the first place Using optional arguments like y = y || 'default' Using number of arguments Checking types of arguments Or how? Getting Started with Unit Testing Unit testing is, roughly speaking, testing bits of your code in isolation with test code. The immediate advantages that come to mind are:  Running the tests becomes automate-able and repeatable You can test at a much more granular level than point-and-click testing via a GUI    My question is, what are the current &quot;best practices&quot; in terms of tools as well as when and where to use unit testing as part of your daily coding? Lets try to be somewhat language agnostic and cover all the bases. Prove that if $k\mid m,$ then $Z_m$ has a subgroup of order $k.$ Prove that if $k\mid m$, then $Z_m$ has a subgroup of order $k.$  Ok, so this doesn't look like too hard of a problem. So do I just show that it is closed under multiplication and inverse? I just don't know how I would do that with a problem like this. Can anyone help me get started please? I often hear about subatomic particles having a property called "spin" but also that it doesn't actually relate to spinning about an axis like you would think. Which particles have spin? What does spin mean if not an actual spinning motion? Anime about a boy and a girl who ride ostrich-like creatures through a valley How to grep standard error stream (stderr)? I am using ffmpeg to get the meta info of an audio clip. But I am unable to grep it.      $ ffmpeg -i 01-Daemon.mp3  |grep -i Duration     FFmpeg version SVN-r15261, Copyright (c) 2000-2008 Fabrice Bellard, et al.       configuration: --prefix=/usr --bindir=/usr/bin        --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib       --mandir=/usr/share/man --arch=i386 --extra-cflags=-O2        ...   I checked, this ffmpeg output is directed to stderr.  $ ffmpeg -i 01-Daemon.mp3 2&gt; /dev/null   So I think that grep is unable to read error stream to catch matching lines. How can we enable grep to read error stream?  Using  link, I redirected standard error stream to standard output stream, then grep worked.  $ ffmpeg -i 01-Daemon.mp3 2&gt;&amp;1 | grep -i Duration   Duration: 01:15:12.33, start: 0.000000, bitrate: 64 kb/s   But what if we do not want to redirect stderr to stdout? I'm trying to  working on Linux. I have PAINSTAKINGLY installed NVidia drivers, Cuda 5.0 and incidentally I'm failing on the last step when I run make:  make  all-recursive make[1]: Entering directory `/var/progs/CudaMiner' Making all in compat make[2]: Entering directory `/var/progs/CudaMiner/compat' Making all in jansson make[3]: Entering directory `/var/progs/CudaMiner/compat/jansson' gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../..     -g -O2 -MT dump.o -MD -MP -MF .deps/dump.Tpo -c -o dump.o dump.c /bin/bash: gcc: command not found make[3]: *** [dump.o] Error 127 make[3]: Leaving directory `/var/progs/CudaMiner/compat/jansson' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/var/progs/CudaMiner/compat' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/var/progs/CudaMiner' make: *** [all] Error 2   I'm pretty sure I have gcc, in fact I have multiple versions of it. I installed version 4.6 (which is what cuda requires) but it doesn't seem to find it. I'm so close!  Thanks in advance. What do we lose passing from the reals to the complex numbers? As normed division algebras, when we go from the complex numbers to the quaternions, we lose commutativity. Moving on to the octonions, we lose associativity. Is there some analogous property that we lose moving from the reals to the complex numbers? Convert XML/HTML Entities into Unicode String in Python I have one Ethernet port that is wired directly to the router on another level.  However, I want to run a desktop and a server both off this one Ethernet port.  Can anyone tell me the difference between an Ethernet splitter and a switch?    Also, will either the splitter or switch slow down the connection as opposed to just one connection? Can't plot with gnuplot on my Mac How to use AT commands in Android by 'root' the phone We have various Android devices from Spike, Samsung, Micromax, etc. How can we issue AT commands from Android to the modem? We searched in Google Play but did not find any app related to this.   suggests:     [F]irst you have to root the phone...`    How can we do this? Although work and heat do the same thing (increase or decrease the internal energy of the system), There is still a fundamental difference between them. For example, The way in which entropy is defined is a very good way to differentiate between work and heat. But, why is there such a distinction between the two things? Is it the limitation of Newtonian mechanics that it never accounted for something like heat which could also change the energy of the system? Is the word "Thermodynamical work" or "Hidden work" suitable for heat? After these instructions in the Python interpreter one gets a window with a plot:  from matplotlib.pyplot import * plot([1,2,3]) show() # other code   Unfortunately, I don't know how to continue to interactively explore the figure created by show() while the program does further calculations.  Is it possible at all? Sometimes calculations are long and it would help if they would proceed during examination of intermediate results. In the example  $\cup^{i=1}_{\infty}F_i$   How do you get the i=1 directly below the union symbol and the infinity directly above? Combine PHP prepared statments with LIKE