I am writing a program that will take a disk file with an array of strings with a max size of 100 and do a few things to them. However, I am getting a console error due to my bubblesort method searching for and trying to sort 100 (the length of the array) items while the disk file may have, lets say, 15 items. The bubblesort method is returning a console error due to it searching for the remaining 85 items and trying to sort 85 blank items. I am totally lost on how to fix this problem. Is it possible to get the items in the disk file, pass them onto another array and then bubblesort that one so the 85 blank spots are eliminated? Or is adding a counter an option that will solve my problem? I am fairly new at java coding so any help would be greatly appreciated.  Here is the error i am getting:   Exception in thread "main" java.lang.NullPointerException at java.lang.String.compareTo(Unknown Source)     at Assignment7.bubbleSort(Assignment7.java:52)     at Assignment7.main(Assignment7.java:12)  here is my code:   import java.io.*;  import java.util.*;  public class Code3 {  public static void main(String[] args) throws IOException {       String[] list2, targets, list1;     list1 = getInput("C:\\Users\\Steave\\Desktop\\file14.txt");     list2 = bubbleSort(list1);                                                 targets = getInput("C:\\Users\\Steave\\Desktop\\upload6.txt");      double seqAvg = seqSearch(list1, targets);     double binAvg = binSearch(list2, targets);     System.out.println("Average number of searches for the seqeuntial search is " + seqAvg);     System.out.println("Average number of searches for the binary search is " + binAvg);  }//end of main method  public static String[] getInput(String filename) throws IOException {     String[] inputArr = new String[100];      Scanner in = new Scanner(new File(filename));     int count = 0;     while(in.hasNext()) {           if (count &lt; 100){             inputArr[count++] = in.next();         } else {             break;         }          }            in.close();     return inputArr;  }// end getInput method     //This method will sort the array and pass it onto a list. public static String[]bubbleSort(String[] inputArr) {      String[] Array2 = inputArr.clone();      for (int i = 0; i&lt;Array2.length; i++)     {       for (int j = 0; j&lt;Array2.length-1; j++)       {           if (Array2[j].compareTo(Array2[j+1]) &gt; 0)         //CONSOLE ERROR HERE           {             String temp = Array2[j];             Array2[j] = Array2[j+1];             Array2[j+1] = temp;           }        }     }       return Array2;  }// End of sort method.  //This method will do a sequential search on the list1 public static double seqSearch(String[] list1, String[] targets){       {           for (int j = 0; j &lt; list1.length; j++)           {               for(String str:targets){               if(list1[j].equalsIgnoreCase(str)){                   return j;               }           }              {                 return j;              }          }          return -1;        }  }//end of sequentialSearch method       //This method will do a binary search on the list      public static int binSearch(String[] list1, String[] targets) {        int lo = 0;         int hi = list1.length - 1;         int mid = -1;          while( lo &lt;= hi ) {           mid = (lo+hi)/2;            for(String str:targets){           if(list1[mid].equalsIgnoreCase(str)){               return mid;           }            hi = mid-1;             } for(String str:targets){           if(list1[mid].equalsIgnoreCase(str)){               return mid;           }       }              lo = mid+1;            {             return mid;           }         }         return mid;       }    }
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?
If a trait would be advantageous to an organism then why hasn't it evolved yet?  Conversely, if a trait is not advantageous or mildly disadvantageous, why does it exist?  In other words why does evolution not make the organism more "perfect"?    This is a general question that would be applicable for any kind of trait. Please keep the answers precise and scientific.   Read this meta post for more information: “Screen overlay detected” dialog? Turned off everything, doesn't work I started receiving the “Screen overlay detected” dialog when trying to change apps settings.  Tried to turn off all "draw over other apps" as it says here - , first without system and then with, but it still doesn't work.  Then, I restored apps to original settings and it just made a bigger mess, dialog continue appearing. Any way to go back to previous settings???  Thanks! How do I figure out the right size font / text for a given read distance? Unable to set DYLD_FALLBACK_LIBRARY_PATH in shell on OSX 10.11.1 prove that if $E$ is connected and $E \subseteq F \subseteq \overline{E}$, then $F$ is connected. Define a set $A$ to be disconnected iff there exist nonempty relatively open sets $U$ and $W$ in $A$ with $U\cap W = \emptyset$ and $A = U\cup W.$ Define a set $A$ to be connected iff it is not disconnected.(there are many equivalent definitions, but I want to prove this lemma using this one). Prove that if $E$ is connected and $E\subseteq F \subseteq \overline{E},$ then $F$ is connected.  Let $U, W$ be a separation for $F$. Find open sets $O_U$ and $O_W$ so that $U = F \cap O_U$ and $W = F\cap O_W.$ I claim that $E\cap O_U, E\cap O_W$ separate $E$. However, I'm unable to show that $U' = E\cap O_U, W' =E\cap O_W \neq \emptyset$ (I think this should be straightforward, but for some reason, I can't figure this out). Suppose $U' = \emptyset.$ Then $E\cap O_U = \emptyset.$ Since $E \subseteq F = U\cup W = F\cap (O_U \cup O_W)\subseteq O_U\cup O_W,$ we have that $E \subseteq O_W,$ so $E\cap O_W = E\subseteq F\cap O_W = W\subseteq F\subseteq \overline{E}.$ Observe that since $E\cap O_U = \emptyset, F\cap O_U = (F\backslash E)\cap O_U\subseteq F\backslash E.$ Similarly, $W'\neq \emptyset.$ Clearly, $U', W'$ are relatively open in $E$. Suppose $U'\cap W' \neq \emptyset.$ Let $x\in U'\cap W'.$ Then $x\in E\cap O_U\cap O_W \subseteq F\cap O_U\cap O_W = U\cap W = \emptyset,$ a contradiction. So $U'\cap W' = \emptyset.$ Also, $U'\cup W' = (E\cap O_U)\cup (E\cap O_W) = E\cap (O_U \cup O_W)$ and $E\subseteq (O_U \cup O_W),$ so $U'\cup W' = E.$ what does ∇ (upside down triangle) symbol mean in this problem Given $f(x) = \frac{1}{2}x^TAx + b^Tx + \alpha $   where A is an nxn symmetric matrix, b is an n-dimensional vector, and alpha a scalar. Show that  $\bigtriangledown _{x}f(x) = Ax + b$   and  $H = \bigtriangledown ^{2}_{x}f(x) = A$   Is this simply a matter of taking a derivative with respect to X, how would you attack this one? Difference between decimal, float and double in .NET? What is the difference between decimal, float and double in .NET?  When would someone use one of these? Best Pattern For Adding Commentary in align Environment? I've been using the align environment to line up equations in proofs/explanations/etc and I like to place parenthetical commentary for each step, similar to the code below:  \documentclass{article} \usepackage{amsmath} \begin{document}  \begin{align*}   f(ax + by) &amp; = f(ax) + f(by) &amp; (By Property 1) \\              &amp; = af(x) + bf(y) &amp; (By Property 2) \\ \end{align*}  \end{document}   The problem I have with this is that the commentary completely distorts the overall alignment of the equation area; far too much space is allocated to the column containing the commentary.  I would like, insofar as it is possible, for the equations themselves to be aligned in the center of the page and for the commentary to simply appear on the right without affecting the overall justification of the equations. What's the best way to achieve this? What is the "Templates" folder in the home directory for? For as long as I can remember, every time I install Ubuntu there is a folder in the home directory called "Templates." I've always just deleted it, but I'm curious: what's it supposed to be used for, and why is it in the default install? Hibernate has a handful of methods that, one way or another, takes your object and puts it into the database. What are the differences between them, when to use which, and why isn't there just one intelligent method that knows when to use what?  The methods that I have identified thus far are:   save() update() saveOrUpdate() saveOrUpdateCopy() merge() persist() Why is /tmp a symlink to /private/tmp on Mac OS X? In other words, why isn't /tmp just a regular directory, like on Linux or BSD? I understand how it works and I don't mind it, I'm just interested in the (historical?) reasoning behind it. What is the difference between a "link function" and a "canonical link function" for GLM Jackknife vs. LOOCV I was looking for some package (nautilus-terminal), and accidentally did this:  $ sudo apt-get install nautilus- Reading package lists... Done                                                                                                                                                                                                  Building dependency tree                                                                                                                                                                                                       Reading state information... Done                                                                                                                                                                                              The following packages were automatically installed and are no longer required:                                                                                                                                                  apturl apturl-common libgail-3-0 linux-headers-4.4.0-57 linux-headers-4.4.0-57-generic linux-image-4.4.0-57-generic linux-image-extra-4.4.0-57-generic                                                                       Use 'sudo apt autoremove' to remove them.                                                                                                                                                                                      The following packages will be REMOVED:                                                                                                                                                                                          gnome-session-flashback nautilus nautilus-sendto nautilus-share ubuntu-desktop                                                                                                                                               0 upgraded, 0 newly installed, 5 to remove and 69 not upgraded.                                                                                                                                                                After this operation, 2 031 kB disk space will be freed.                                                                                                                                                                       Do you want to continue? [Y/n] ^[[^C                                                                                                                                                                                             That's quite dangerous because remove is much harder to mistype than a simple dash from a failed autocompletion.     Is that an equivalent of apt-get remove? I couldn't find any documentation for that. Edit: except for overlooking the man page... Imported TIF has dark gray background instead of white using QGIS 2.6  I import a TIF file, and expect the import to show an image that has black lines on a white background (with some other colors here and there), as the native windows viewer will see a white background.   The file, 49MB, imports, but   The TIF image has a dark gray background instead of a white background  I can't tell why.   Any hints?  The same thing happens if I import the TIF image into georeference, which is how I discovered this in the first place.  I created/exported the TIF image using PDFCreator (from a print of a PDF to a TIF, using that program).   Within PDFCreator, I chose a TIF export that set the color map to 4096 colors, as the default created a TIF file that was twice as large.  On testing with the default size (16 million colors or some such).... That file imported and showed the background as white.  And I can't tell why, for that, either.   Any hints?  ======== In response to the comment/question by @BradHards:  The TIFFTAG_PHOTOMETRIC is not present in either file.  The gdalinfo for the large file and small file are identical, but for the presence of two extra lines on the file where the white background turns to dark gray.  Each band sets NBITS=4 for Image Structure Metadata: eg:     Band 1 Block=5100x68 Type=Byte, ColorInterp=Red   Image Structure Metadata:     NBITS=4 Band 2 Block=5100x68 Type=Byte, ColorInterp=Green   Image Structure Metadata:     NBITS=4 Band 3 Block=5100x68 Type=Byte, ColorInterp=Blue   Image Structure Metadata:     NBITS=4   Something about the NBITS=4 state turns the background dark gray.  Alternatively, there is some other problem with the PDFCreator export.  These are the full GDALInfo:  Small with dark gray background:   Driver: GTiff/GeoTIFF Files: small file.tif Size is 5100, 6600 Coordinate System is `' Metadata:   TIFFTAG_DATETIME=2015:01:28 16:41:04   TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)   TIFFTAG_SOFTWARE=GPL Ghostscript 9.07   TIFFTAG_XRESOLUTION=600   TIFFTAG_YRESOLUTION=600 Image Structure Metadata:   INTERLEAVE=PIXEL Corner Coordinates: Upper Left  (    0.0,    0.0) Lower Left  (    0.0, 6600.0) Upper Right ( 5100.0,    0.0) Lower Right ( 5100.0, 6600.0) Center      ( 2550.0, 3300.0) Band 1 Block=5100x68 Type=Byte, ColorInterp=Red   Image Structure Metadata:     NBITS=4 Band 2 Block=5100x68 Type=Byte, ColorInterp=Green   Image Structure Metadata:     NBITS=4 Band 3 Block=5100x68 Type=Byte, ColorInterp=Blue   Image Structure Metadata:     NBITS=4   Large with white background   Driver: GTiff/GeoTIFF Files: larger file.tif Size is 5100, 6600 Coordinate System is `' Metadata:   TIFFTAG_DATETIME=2015:01:28 17:07:16   TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)   TIFFTAG_SOFTWARE=GPL Ghostscript 9.07   TIFFTAG_XRESOLUTION=600   TIFFTAG_YRESOLUTION=600 Image Structure Metadata:   INTERLEAVE=PIXEL Corner Coordinates: Upper Left  (    0.0,    0.0) Lower Left  (    0.0, 6600.0) Upper Right ( 5100.0,    0.0) Lower Right ( 5100.0, 6600.0) Center      ( 2550.0, 3300.0) Band 1 Block=5100x68 Type=Byte, ColorInterp=Red Band 2 Block=5100x68 Type=Byte, ColorInterp=Green Band 3 Block=5100x68 Type=Byte, ColorInterp=Blue How to permanently set environmental variables My variables are   LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib ORACLE_HOME=/usr/lib/oracle/11.2/client64   How to save these variables permanently ? Is it possible to programmatically change connectedApp settings in production? Background: I have a requirement to make it so that an SFDC connected app defaults/is super easy to set to Admin Users are Pre-authorized instead of All users may self-authorize. This setting is important to make this app work and we have historically have had problems with admins not configuring this setting correctly.  Here is a quick history on what I have tried to do to get the isAdminApproved set to "true":   Directly, via xml definition (doesn't get honored) Directly via apex code (doesn't get honored)  (ended up being more pain than what it was worth and was told that it wouldn't work in prod because of security restrictions) Indirectly via a connected-app connected service to make a metadata API call: works in a scratch org but not in prod, which I assume is because it is a managed package. This would occur when an Admin clicks on a button, not from a post-install script.   Details on what I mean by it isn't working in prod: When I try to do a readMetadata call on my connectedApp objects that are in my managed package, the response comes back as [{\n    'fullName': None\n}] instead of with the metadata configuration of my connected app.  Here is a sequence diagram of what I am trying to do in #4 right now:    My question is this: Am I on a fool's errand, where this is impossible to do? ...Or is there a way to set a connected app (in a managed package that I publish) to Admin Users are Pre-authorized without making the admin just do it themselves directly in the settings? Why isn't The Flash unstoppable? I've recently gotten into The Flash TV show, and so I've been reading about his powers. What I don't understand is why his typical rogues pose a threat - it seems like there should be very little limit to his powers.  He can go back in time, so if he loses a battle or the bad guys do something, he can go back and preempt it. In the new 52, he can all but predict the immediate future, so he can see bad things that are going to happen and stop them. He can phase matter through matter, or let matter pass through him. This means he is all but immune to weapons fire.  I haven't read enough of the old comics so I don't the know challenges he's had. For a guy who can't be attacked, can time-travel and can race around the globe several times in a minute, I can't imagine there is much that could pose a threat. I was surprised to find that standalone package can not compile a document with an equation:  \documentclass{standalone} \begin{document} \begin{equation} % not working! F(V, T) = E(V) + D(T) \end{equation} \end{document}   Is there an option or some workaround that allows this? The current error is something like:   ! Missing $ inserted.   in line 4. (The idea of course is that the including (main) document can just \input the standalone without knowing if is going to be an equation or something else) Some speculation here:   Is there a possibility it would pass 'undetected' through your hand, or is it certain death?  Can you conclude it to be vital, or only loose your hand?  Would it simply make a small cylindrical hole through your hand, or is there some sort of explosion-effect?  Assume your hand has a cross section of 50cm², and a thickness of 2cm, how much of the beam's energy would be transferred to your hand?