I am trying to write the game 2048 in java, right now I only make one row to understand how it works. Using      HashMap and using      Collection.shuffle  method to get the random Point position. When I run my code, it places the random number in a random spot, but I also got the syntax error,      "Exception in thread "main" java.lang.NullPointerException"  and it shows the problems are in my Model class my      getValue(int row, int column)     notificationToView()  What is the error referring to? How can I fix it?   import java.util.Random; import java.awt.Point; import java.util.Collections; import java.util.HashMap; import java.util.ArrayList;   public class Model  {      View _view;  private HashMap&lt;Point, Integer&gt; _map;      public Model(){         _map = new HashMap&lt;Point, Integer&gt;();          for(int i = 0; i &lt; 4; i++)             _map.put(new Point(0,i), -1);   }   /**  * Assigns randomly generated int values to the   * variables of the model.  */ public void notificationToView() {          _map.put(getRandomPoint(), getRandom2OR4());      _view.updateView(); }    public int getRandom2OR4(){     Random r = new Random();      if(r.nextInt() % 5 == 0 )             return 4;     else         return 2;                }  public Point getRandomPoint(){       ArrayList&lt;Point&gt; unoccupied = new ArrayList&lt;Point&gt;();      for (int i = 0; i &lt; 4; i++)     {         if(_map.get(new Point(0,i)) == -1)             unoccupied.add(new Point(0,i));     }      Collections.shuffle(unoccupied);     Point random = unoccupied.get(0);       return random; }  public int getValue( int row, int column) {     return  _map.get(new Point(row, column)); }   /**  * Method that associates the a view as an observer  * of the model.  Being an observer implies receiving  * notifications when the data in the model changes.  */ public void addObserver(View view) {     _view = view; }  }     public class View implements Runnable {     private JFrame _frame;     private JPanel _panel;     private Model _model;     private ArrayList&lt;JButton&gt; _list;      public View(Model m){         _model = m;       }    /**    * This method updates the view based on the current    * values stored in the data model.    */    public void updateView() {          for(int i = 0; i &lt; 4; i++){             if(_model.getValue(0,i) != -1)                 _list.get(i).setText("" + _model.getValue(0, i));             else                  _list.get(i).setText("");     }     }      @Override     public void run() {          _list = new ArrayList&lt;JButton&gt;();         _frame = new JFrame("Lab7");         _panel = new JPanel();         // create 4 buttons          for(int i = 0; i &lt; 4; i++){              JButton buttons = new JButton();             _list.add(buttons);                 _panel.add(_list.get(i));              _list.get(i).setFont(new Font("Georgia", Font.PLAIN,40));             _list.get(i).addKeyListener(new MyKeyEvent(_model));    }
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?
Let $\{f_n\}$ be a sequence of analytic functions on a region $\Omega$ with $|f_n| ≤ 1$ on $\Omega$. Let K be compact and contained in $\Omega$. Suppose $\{f_n\}$ converges at infinitely many points in K. Then is it true or false that $\{f_n\}$ necessarily converges at every point of $\Omega$? Notation for infinite product in reverse order This question is related to notation of infinite product.   We know that, $$ \prod_{i=1}^{\infty}x_{i}=x_{1}x_{2}x_{3}\cdots $$  How do I denote $$     \cdots x_{3}x_{2}x_{1}  ?    $$  One approach could be  $$ \prod_{i=\infty}^{1}x_{i}=\cdots x_{3}x_{2}x_{1} $$  I need to use this expression in a bigger expression so I need a good notation for this. Thank you in advance for your help. Evaluation order of Button's action Continuity of absolute value of a function Let $f(x)$ be a continuous function. Prove that $\left|f(x)\right|$ is also continuous.  Is it correct to say that, by the reverse triangle inequality, $\left|f(x)-f(c)\right| \geq \left|f(x)\right|-\left|f(c)\right|$ in all cases, so we will always have that for all $\left|x-c\right|&lt;\delta$ implies $\left|f(x)-f(c)\right|\leq \epsilon$?  I am not sure if my solution adequately uses the functional form, since I just used the equation and not my actual function. Please help with the proper solution! I'm working on creating an illustration that I will need in many, different guises in differential geometry/manifold theory etc. Following on from a previous (answered) question of mine (, I want to show how two coordinate lines in the plane originate from two curves on a surface via the chosen map:  \begin{tikzpicture}     \begin{axis}[             name=mfd,             declare function={                     f(\x,\y)=10-(\x^2+\y^2);             },                   declare function={                     c_x(\t)=(cos(\t)+(sin(5*\t)/10))/3+1;             },                   declare function={                     c_y(\t)=(sin(\t))/2-1;             },                   declare function={                     c_z(\t)=f(c_x(\t),c_y(\t));             },           ]                    \addplot3[surf,domain=-2:2,domain y=-2:2,]{f(x,y)};             \addplot3[black,opacity=1.0,variable=t,domain=0:360,dashed,thin] ({c_x(t)},{c_y(t)},{c_z(t)});             \addplot3[black,opacity=1.0,variable=t,domain=-2:2,thin] (t,-1.2,{f(t,-1.2)});             \addplot3[black,opacity=1.0,variable=t,domain=-2:2,thin] (0.8,t,{f(t,-1.2)});             \addplot3[black,opacity=1.0,only marks,mark=text,text mark=$\cdot$] (1,-1,{f(1,-1)}) coordinate (a);     \end{axis}     \begin{axis}[             at={($(mfd.north east)+(1cm,-2cm)$)},             anchor=north west,             declare function={                     c_x(\t)=(cos(\t)+(sin(5*\t)/10))/3+1;             },                   declare function={                     c_y(\t)=(sin(\t))/2-1;             }            ]                    \addplot[variable=t,domain=0:360]({c_x(t)},{c_y(t)});             \addplot[black,opacity=1.0,only marks,mark=text,text mark=$\cdot$] (1,-1) coordinate (b);             \addplot[variable=t,domain=0.6:1.4](t,-1.2);             \addplot[variable=t,domain=-1.5:-0.5](0.8,t);     \end{axis}     \draw [-stealth, shorten &lt;= 3pt, shorten &gt;= 3pt] (a) to[bend left] (b); \end{tikzpicture}   However, I have a couple of problems:   The curves representing the coordinate axes pulled back from the plane via the coordinate map insist on being closed off with a straight line - is there a way to avoid that? I want to draw all the black curves with a thin, dashed line, but I probably don't understand how to set those options. What am I doing wrong?   I apologise if these questions are rather elementary, but I find the relevant manuals difficult to search through; they seem to be meant for reading cover to cover rather than reference. Show that $\cot \frac{\pi}{2m}\cot \frac{2\pi}{2m}\cot \frac{3\pi}{2m}...\cot \frac{(m-1)\pi}{2m}=1$ I was going to ask , but I came to the conclusion that I'm not going to do it (asking and building).  Now my question is: why is it (usually, if we leave the silly high-end prices alone) more expensive to build a bike from scratch? Why do some tests have a (nonzero) minimum score? Calculating determinant with different numbers on diagonal and x everywhere else I'm having troubles solving the following determinant:  $$\left|   \begin{array}{cccc}     a_1 &amp; x &amp; \ldots &amp; x \\    x &amp; a_2 &amp; \ldots &amp; \vdots \\     \vdots &amp; \ldots &amp; \ddots &amp; x \\     x &amp; \ldots &amp; x &amp; a_n \\   \end{array} \right|$$  I have tried coming up with recurrent formula, but there's always one lingering row and column. I also tried finding values of x for which determinant is 0, hoping I could get a nice polynomial solution, with no luck.  By subtracting first row from every other I get somewhat nicer result, but there's still that one row/column which I can't solve. If all other columns are added to the first one and then I subtract the first row, then the column doesn't depend on x anymore, but I haven't found 1..n much more useful. How can I do the following in Git?  My current branch is branch1 and I have made some local changes. However, I now realize that I actually meant to be applying these changes to branch2. Is there a way to apply/merge these changes so that they become local changes on branch2 without committing them on branch1? How can I see flags I cast from all sites? Notation problem in integration: write $dx$ or ${\mathrm{d}}x$? Assume $f$ and $g$ are differentiable at $x$. Prove that $(fg)^{(n)} = \sum_{k=0}^n \binom{n}{k}f^{(k)}(x)g^{(n-k)}(x)$   I am assuming here $fg = f(x) g(x)$. Then we can prove this via induction. If $n = 0$ we have $1 = 1$ which is true. Now assume it is true for some $m$ we need to show it is possible for $m+1$. We have $(fg)^m = \sum_{k=0}^m f^{(k)}(x)g^{m-k}(x)$. How do we show that? A story about a guy who helped humanity by being held in a prison I remember a story I have read buy could not remember the author the name or anything apart from the basic plot. The story is about some future where humanity has to fight with some aliens (not 100% sure). The story tells about a guy who was some kind of activist and who was in a prison two or more times and somehow helped humanity by being held in a prison (can't remember details). I think the story starts by saying that there is a statue in his honor that is not very well known but he did more to help humanity than famous politicians.   The story is most likely written by some famous English-speaking author, though I read it in a translation. With java.sql.ResultSet is there a way to get a column's name as a String by using the column's index? I had a look through the API doc but I can't find anything. how to show image in table cell through json parsing One of my laptop's keys has fallen off. Is there any way I can remap another key to serve as that key?  I'll 'sacrifice' the other key because I never use it. E.g.: If your Gmail ID is abc.xyz@gmail.com, it considers this the same as abcxyz@gmail.com.  Why is this so? How Do Dementors Communicate with Wizards? How can I strike through an expression (e.g. "2x") obliquely, e.g. from bottom left to top right, so as to indicate cancellation? With the \sout command from the ulem package, I can only strike horizontally.