So I am sort of new to Java and have only been doing it for a couple of months. I'm trying to implement different types of sorting algorithms and I think everything is okay except when I run it I get a NullPointerException on the for loop. I have already read this post . But I still can not figure out how to fix the problem even though I think it is quite simple. Any help?  import java.lang.*; import java.util.*;  public class SortApp {      public int[] generateRandomArray(int size) {          int[] output = new int[size];         for (int i = 0; i &lt; size; i++) {             output[i] = (int) (Math.random() * Integer.MAX_VALUE);         }         return output;     }      public void printArray(int[] inarray) {          for (int i = 0; i &lt; inarray.length; i++) {             System.out.println(inarray[i]);         }     }      public boolean isSorted(int[] inarray) {         for (int i = 0; i &lt; inarray.length; i++) {       //Error here             if (inarray[i] &gt; inarray[i + 1]) {                 return false;             }         }         return true;     }      public int[] insertionSort(int[] inarray) {          int[] data = Arrays.copyOf(inarray, inarray.length);         int temp;         int j;         for (int i = 0; i &lt; inarray.length; i++) {             temp = inarray[i];             for (j = 0; (j &gt; 1) &amp;&amp; (temp &lt; inarray[j - 1]); j--)                 inarray[j] = inarray[j - 1];             inarray[j] = temp;         }         return data;     }      public int[] selectionSort(int[] inarray) {          int[] data = Arrays.copyOf(inarray, inarray.length);         int temp;         int n = inarray.length;         for (int i = 0; i &lt; inarray.length; i++) {             int k = i;             for (int j = i + 1; j &lt; n; j++)                 if (inarray[j] &lt; inarray[k])                     k = j;             temp = inarray[i];             inarray[i] = inarray[k];             inarray[k] = temp;         }         return data;     }      public int[] mergeSort(int[] inarray, int temp[], int l, int r) {          int[] data = Arrays.copyOf(inarray, inarray.length);          if (l == r) return null;         int mid = (l + r) / 2;         mergeSort(inarray, temp, l, mid);         mergeSort(inarray, temp, mid + 1, r);          int i, j, k;         for (i = l; i &lt;= r; i++)             temp[i] = inarray[i];         for (i = l, j = mid + 1, k = l; i &lt;= mid &amp;&amp; j &lt;= r &amp;&amp; k &lt;= r; k++)             if (temp[i] &lt; temp[j]) inarray[k] = temp[i];         i++;         inarray[k] = temp[j];         j++;         for (; i &lt;= mid; i++, k++)             inarray[k] = temp[i];         for (; j &lt;= r; j++, k++)             inarray[k] = temp[j];          return data;     }      public static void main(String[] args) {         SortApp myApp = new SortApp();         int[] data = myApp.generateRandomArray(10);          boolean isSortedA = myApp.isSorted(myApp.insertionSort(data));         boolean isSortedB = myApp.isSorted(myApp.selectionSort(data));         boolean isSortedC = myApp.isSorted(myApp.mergeSort(data, data, 0, 0)); //Error here         myApp.printArray(data);     } }   Error I am getting is this:  Exception in thread "main" java.lang.NullPointerException at SortApp.isSorted(SortApp.java:23) at SortApp.main(SortApp.java:91)
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?
Accessing the index in 'for' loops? How can I determine which process owns a hotkey in Windows? Given a hotkey, how can I find which program owns it? Emmy Noether's theorem in simpler terms I'd like to understand  and its contents as to what it implies in a bit simpler terms. I am familiar with mathematics unto Calculus 1,2,3 and some linear algebra and group theory. I am familiar with that for each symmetry there is a conservation law.    Now is there a one-one correspondence between these two always? What about laws like conservation of charge?  And conservation of energy?  And conservation of mass?  Considering our view of nature was changed as Special Relativity was introduced and thus, what earlier the theorem would have asserted as mass and energy to be originating from different symmetries then how did we reconcile these two as just one symmetry? How to upgrade Ubuntu from an ISO image I'm using Ubuntu 10.04 now and want to Upgrade to Ubuntu 11.04. The problem is my net connection is very slow and I can not do a network upgrade from the "Updates Manager".  So, is there a way that I can download the Ubuntu upgrade as an bootable CD image and upgrade from it? Dynamic SELECT TOP @var In SQL Server How can I have a dynamic variable setting the amount of rows to return in SQL Server? Below is not valid syntax in SQL Server 2005+:  DECLARE @count int SET @count = 20  SELECT TOP @count * FROM SomeTable How to sort an array of integers correctly Lag compensation with networked 2D games I want to make a 2D game that is basically a physics driven sandbox / activity game. There is something I really do not understand though. From research, it seems like updates from the server should only be about every 100ms. I can see how this works for a player since they can just concurrently simulate physics and do lag compensation through interpolation.  What I do not understand is how this works for updates from other players. If clients only get notified of player positions every 100ms, I do not see how that works because a lot can happen in 100ms. The player could have changed direction twice or so in that time. I was wondering if anyone would have some insight on this issue.  Basically how does this work for shooting and stuff like that?  Thanks On Travel.SE we often see questions about a person (usually a love interest) asking for money to pay for airfare, visas, permits and other expenses. For example        What general advice can be given in such situations to the person asking the question? Is it all a scam or can there be legitimate situations in which an online friend could be asking for money? Supersymmetry in Quantum Field Theory How to stop apt from doing anything How do you run a Python script as a service in Windows? I am sketching the architecture for a set of programs that share various interrelated objects stored in a database. I want one of the programs to act as a service which provides a higher level interface for operations on these objects, and the other programs to access the objects through that service.  I am currently aiming for Python and the Django framework as the technologies to implement that service with. I'm pretty sure I figure how to daemonize the Python program in Linux. However, it is an optional spec item that the system should support Windows. I have little experience with Windows programming and no experience at all with Windows services.  Is it possible to run a Python programs as a Windows service (i. e. run it automatically without user login)? I won't necessarily have to implement this part, but I need a rough idea how it would be done in order to decide whether to design along these lines.  Edit: Thanks for all the answers so far, they are quite comprehensive. I would like to know one more thing: How is Windows aware of my service? Can I manage it with the native Windows utilities? What is the equivalent of putting a start/stop script in /etc/init.d? How do I Uninstall Windows 10 or Windows 10 preview? I want to define \ext to behave exactly like \lim.  I tried \newcommand{\ext}{{\mathrm{ext}}\,} but that doesn't behave exactly like \lim. TV show that starts with debris encompassing Earth Why are two permutations conjugate iff they have the same cycle structure? Taylor's polynomial uniqueness proof - why are these limits inferable? So I'm viewing a short proof on the uniqueness of Taylor polynomials.     Uniqueness of Taylor polynomial:   Let $f:]a,b,[ \rightarrow \mathbb{R}$ $n$ times continuously   differentiable and $x_0 \in ]a,b,[$. If $p$ is $n$th degree polynomial   function for which       $$f(x)-p(x)=o(|x-x_0|^n), \space \text{when} \space x \rightarrow x_0$$  then      $$p(x)=T_{n, x_0} f(x)$$   Proof starts like:  $$\frac{p(x)-T_{n, x_0}f(x)}{(x-x_0)^n} = \frac{p(x)-f(x)}{(x-x_0)^n}+\frac{f(x)-T_{n, x_0}f(x)}{(x-x_0)^n}$$  then   $$\frac{p(x)-f(x)}{(x-x_0)^n} \rightarrow 0 \space, when \space x-x_0 \rightarrow 0$$  $$\frac{f(x)-T_{n, x_0}f(x)}{(x-x_0)^n} \rightarrow 0 \space, when \space x-x_0 \rightarrow 0$$  Now my problem is, how can one actually say that the above approach $0$ if the denominator approaches $0$? How do I invoke a Java method when given the method name as a string? Give the "some of your recent flags have been declined" banner some room The "some of your recent flags have been declined" message recently got a banner, which makes it stand out  more (which is nice) but it touches the 'Flag' button, which is less nice. Can it have some margin at the bottom (and perhaps less padding?)    Tested in the latest Safari and Firefox on macOS Catalina. How is a generator found for a group, both in case of DH & ECDH? I'm trying to use arcpy to save an .mxd and am having an issue.  It doesn't matter if I use mxd.save or mxd.saveACopy I get the same error.  I know it doesn't look like I am doing anything w/ it here, but it's just a portion of my code:  import arcpy import arcpy.mapping as map arcpy.env.overwriteOutput = True  env.workspace = r"C:\MGIS\FinalProject2.gdb     mxd = map.MapDocument(r"C:\MGIS\Finalproject2.mxd") df = map.ListDataFrames(mxd)[0]  for df in map.ListDataFrames(mxd): df.scale = 2000000  #Add layers into map document addLayer = map.Layer(OKXcounties) addLayer1 = map.Layer(contourLabelText) addLayer2 = map.Layer(contoursClipLyr) addLayer3 = map.Layer(clipOKXLyr) map.AddLayer(df, addLayer, "AUTO_ARRANGE") map.AddLayer(df, addLayer1, "AUTO_ARRANGE") map.AddLayer(df, addLayer2, "AUTO_ARRANGE") map.AddLayer(df, addLayer3, "AUTO_ARRANGE")  # Add contour Labels for lyr in map.ListLayers(mxd):     if lyr.name == "contourLabelText":         lyr.showLabels = True     if lyr.name == "Contour Features":         lyr.transparency = 100  mxd.saveACopy(mxd)   I get the following error:   Traceback (most recent call last):   File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript     exec codeObject in __main__.__dict__   File "C:\MGIS\geog485\FinalProject2\mxdtest.py", line 7, in &lt;module&gt;     mxd.saveACopy(mxd)   File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_     return fn(*args, **kw)   File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 668, in saveACopy     self._arc_object.saveACopy(file_name) AttributeError: MapDocObject: Unable to save.  Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.   Space is not the issue, I have 60 GB of free space and I've checked the windows properties of the .mxd file.  Read-only box is unchecked and I've "allowed" all permissions for all groups:    Does anyone have any idea how if this is a bug or how I can fix this?  I'm using ArcInfo 10.0 SP4.