This is my take on the question "Longest Palindrome Substring"(Leetcode problem  ). So, I tried iterating through each substring to see whether they are palindrome or not and stored the palindromic substring with its length in a map.  But, when accessing the key (string:- "aba") using the value (int:- 3), I'm getting the error " Line 27: java.lang.NullPointerException".   I tried giving test cases of ignoring strings with length less than 3, but i'm still encountering the issue, where longer strings works fine.   class Solution {     public String longestPalindrome(String s) {         ArrayList&lt;String&gt; arr = new ArrayList&lt;&gt;();         arr = allSubStr(s);         if(s == null || s.length() &lt;= 2)             return s;         //System.out.println("before" + arr);         for(int i = 0; i &lt; arr.size(); i++){             if(!isPali(arr.get(i))){                 arr.remove(i);             }         }         //System.out.println("after" + arr);         Map&lt;String, Integer&gt; map = new HashMap&lt;&gt;();         for(int i =0; i &lt; arr.size(); i++){             map.put(arr.get(i), arr.get(i).length());         }         Map.Entry&lt;String, Integer&gt; maxEntry = null;         String maxVal = "";         for (Map.Entry&lt;String, Integer&gt; entry : map.entrySet()){             //System.out.println(maxEntry.getValue());             if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) &gt; 0){                 maxEntry = entry;                 maxVal = entry.getKey();             }         }         return maxEntry.getKey();      }     public static boolean isPali(String str){         int i =0;         int j = str.length() -1;         char[] word = str.toCharArray();         while(j &gt; i){             if(word[i] != word[j])                 return false;             i++;             --j;         }         return true;     }      public static ArrayList&lt;String&gt; allSubStr(String str){         ArrayList&lt;String&gt; temp = new ArrayList&lt;&gt;();         for(int i =0; i &lt; str.length(); i++){             for(int j =i+1; j &lt; str.length(); j++){                 temp.add(str.substring(i,j));             }         }         for(int i =0; i &lt; temp.size(); i++){             if(temp.get(i).length() &lt; 2){                 temp.remove(i);             }         }         return temp;     } }   So, can anyone point out, where I am making the mistake? The output should be "aba" when given a string "babad" or any of its alternative.  Thanks in advance!
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?
Can I apply for a Schengen visa of the first port of entry or does it need to be the country of the longest duration? I'm planning to travel to the Netherlands, Spain and Bulgaria. My longest stay will probably be in Bulgaria. Now, Bulgaria doesn't issue a Schengen visa but allows people with a Schengen visa to visit. Which visa should I be applying for? Bulgarian Visa AND Schengen visa or just the Schengen visa for Netherlands or Spain? Vertex groups can not be named in blender 2.70 For some reason the name text field doesn't appear for vertex groups in blender 2.70. I tried in 2.69 and it's there and works fine. Was this feature removed in 2.70 or am I missing something? Since version 3.2, uTorrent displays ADs in the form of a "Featured Torrent" banner and a small square advertising in the sidebar. Is there a way to disable those? How do I install fonts? Question says it all. I need them to be available in gimp. Trigonometry Olympiad problem: Evaluate $1\sin 2^{\circ} +2\sin 4^{\circ} + 3\sin 6^{\circ}+\cdots+ 90\sin180^{\circ}$ Find the value of   $$1\sin 2^{\circ} +2\sin 4^{\circ} + 3\sin 6^{\circ}+\cdots+ 90\sin180^{\circ}$$   My attempt  I converted the $\sin$ functions which have arguments greater than $90^\circ$ to $\cos$ but I have gone no where with it!  I also tried using double angle formula for the angles which are even. Why did the Tethered form a line in Us? In Jordan Peele's  we see that the Tethered plan a revolt, rise above ground and start murdering everyone in sight and then they form a line by holding hand in hand.   What was the purpose of that? Make clear which profile data is visible to whom I was confused, trying to copy some files from one PC to another. I have it figured out, but the syntax is still confusing to me. This works:  scp ~/Desktop/Volenteer.png jay@server.ip:~j0h/b   which puts Volenteer.png in the folder /home/j0h/b.  However, this doesn't work:  scp ~Desktop/Volenteer.png     jay@server.ip:~j0h/b   This also fails, giving an exit status 1 file not found:  scp ~/Desktop/Volenteer.png     jay@server.ip:~/j0h/b   As does this:  scp ~Desktop/Volenteer.png     jay@server.ip:~j0h/b   So clearly, there is some difference between ~ and ~/ That difference is the presence of /   $~/ bash: /home/j0h/: Is a directory $ ~ bash: /home/j0h: Is a directory   So why in scp, does the ~ resolve to ~/ ? That is a guess, I cant verify that's what is happening.  But it seems inconsistent, and therefore confusing.  Is this a bug in scp? or is there something about tilde I am missing? Fixed point of a Function (monotonically increasing) How to debug "Cross-thread operation not valid" error in C#? Situation: when a user self-marks their post as a duplicate, it shows as closed by "community" rather than the original poster.  Problems: this is not clear at all to most users of SE what has happened. It looks like the question was "mod closed" as a duplicate against the asker's wishes.    Suggestion: instead of the community user "closing" the post, have the final close user be the asker (or make it "Community &amp; Asker"). This will help clear up confusion and streamline the process for understanding what happens. Why does $\lim_{n \to\infty}a_{n+1} = \lim_{n\to\infty}a_n$? Assume that $\{a_n\}$ is a convergent sequence. How to use the definition of a limit of a sequence to prove that $\lim\limits_{n \to\infty}a_{n+1} = \lim\limits_{n\to\infty}a_n$? Bash is not finding a program even though it's on my path I have a program on my path.  The program runs when executed with a full path specified.  But the program cannot be found when I run it with just its name.    Essentially, I want to understand how the below output is possible, and how to fix it so that my program can actually be found without a full path specified:  root:/usr/local/bin# ./siege **************************************************** siege: could not open /usr/local/bin/etc/siegerc run 'siege.config' to generate a new .siegerc file **************************************************** root:/usr/local/bin# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games root:/usr/local/bin# siege bash: /usr/bin/siege: No such file or directory root:/usr/local/bin# wtf!?!?   I'm on Ubuntu 12.04 using bash.  Also please note the warning output from siege is not relevant for the purposes of this question, as I am only interested in whether or not the program can be found and invoked. Recently I've changed jobs, and consequently the field of research has also changed. But I'm still getting proposals for publications in the previous field, and it is interesting for me to accept some of them. My concern is about which affiliation to use: on one hand I gain all the knowledge in that field while working on the previous employer, also I hope they can cover my expenses related to the publication. On the other hand, I do not work for them anymore, and my current company has very little interest in my old field of research, and probably will not support it financially, but I think it is wise to mention them as well. As a compromise I'm thinking to put the previous employer in the affiliation, and the name of my new employer in the footnote, something like "currently at XYZ". Surely I'll discuss this issue with both, although the opinion of the community is also very valuable. Possible Duplicate:             I faced this issue today when I was replying to a comment posted which used @Transaction annotation.     @Trevor: @Transaction and ... @Transaction   When typing this comment, I got a warning. Installing two glibc alongside in debian/ubuntu Is it possible to install and use two different glibc versions on the same machine. Where one version is only used to run legacy software, which relies on old glibc binaries?  Is it possible to do that with the aid of the package manager (something like "install this package, and its dependencies, to /opt/old-glibc), instead of managing it dire What are the pros and cons of adding a vapor barrier behind shower backer board? After much research, I have a lot of conflicting advise about the need to add a vapor barrier before installing the backer (hardy / cement) board for my bathroom shower. The &quot;expert&quot; at Home Depot, and  seem to think this is a very good idea, and even suggest sealing it with roofing tape.  (The guy on Youtube tapes it directly to the sill of tub.) However, when I asked about the tape and how far down I should go at Lowes, they told me they'd never hear of anyone doing that, and that it didn't seem like a good idea.   Likewise,  putting down caulking on the sill before applying the backer board, and then again after before adding tile, and then caulking a 3rd time under the tiles before grouting. Should I add a vapor barrier between the frame and the cement board?  Why or why not? Windows Spotlight Source and Save locations? What is the coefficient of the term $a^i b^j c^k$ in the expansion of $(a+b+c)^n$? What is the coefficient of the term $a^i b^j c^k$  in the expansion of   $(a+b+c)^n$ ?   Given solution:     Before collecting like terms, each term in the expansion is a product   of $n$ factors each  of which is $a, b,$ or $c$.  Those terms which   have exactly i a’s, j b’s and k c’s can be combined into   the single term $a^i b^j c^k$ and the number of such terms will be   equal to the number of n letter strings containing i a’s, j b’s and k   c’s, which by the Mississippi rule is $\frac{n!}{(i!\times j! \times  k!)}$.   I understand that this problem is actually about the derivation of the coefficient of the multinomial theorem,but I am not sure about the combinatoric reasoning,what I mean is that I understand the analogy problem but what I couldn't is how the analogy holds here,Could anybody explain this to me? Understanding the "Birthday Problem"