I am trying to initialize an array grid of objects and get a null point error when I do so. It should be calling the object Constructor in Cell each iteration of the loop.  Instead I am getting the error. Please help. public class Spread extends JPanel {     private JPanel outputArea;     private JTextArea numberDead;     private JTextArea totalInfected;     private JTextArea newInfections;     private Integer totalDead;     private Integer total;     private Integer newInfected;     private Integer length = 60;     private Integer width = 100;     private Cell[][] label;          public void makeOutputArea() {         int a;         int b;         outputArea = new JPanel(new GridLayout(length, width, -1, -1));         outputArea.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));          for (a = 0; a &lt; (length - 1); a++){             for (b = 0; b &lt; (width - 1); b++)                 label[a][b] = new Cell(); //nullpointerror is located here.                 label[a][b].setPreferredSize(new Dimension(10, 10));                 label[a][b].setOpaque(true);                 outputArea.add(label[a][b]);                 outputArea.setVisible(true);                 if (label[a][b].getInfected() == true) ++total;             }         }          public JPanel getOutputArea() {         return outputArea;     } ...Additional code follows.  This is the Cell class it should be initializing in the array. As you can see it has a constructor, which should be called for each loop.  Instead it is giving a null pointer and never initializing each cell object. import java.awt.Color; import java.util.Random; import javax.swing.JLabel;  @SuppressWarnings(&quot;serial&quot;) public class Cell extends JLabel{     private int iteration;     private boolean infected;     private boolean dead;     private boolean immune;     private Random generator = new Random(); //Random number Generator     private static int infectionRate = 5;     private static int deathRate = 3;               public void setIteration(int i) {         iteration = i;     }          public int getIteration() {         return iteration;     }          public void setInfected(boolean b) {         infected = b;     }          public boolean getInfected() {         return infected;     }          public void setDead(boolean a) {         dead = a;     }          public boolean getDead() {         return dead;     }          public void setImmune(boolean i) {         immune = i;     }          public boolean getImmune() {         return immune;     }          public Cell() {         setImmune(false);         setDead(false);         setIteration(0);         if (generator.nextInt(100) &lt; infectionRate) {             setInfected(true);             setIteration(++iteration);         }         else setInfected(false);         color();     }          public void color() {         if (getInfected() == true) setBackground(Color.RED);         else if (getDead() == true) setBackground(Color.BLACK);         else setBackground(Color.GREEN);     }          public void updateInfection(boolean b) {         try {             if (getImmune() == true) return;             else if (getDead() == true) return;             else if (getInfected() == true) {                 setIteration(++iteration);                 if (iteration &gt;=4) {                     if (generator.nextInt(100) &lt; deathRate) {                         setInfected(false);                         setDead(true);                         return;                     }                     else {                         setInfected(false);                         setImmune(true);                         return;                     }                 }                 return;             }             else {                 if (generator.nextInt(100) &lt;= 75) {                     setInfected(true);                     setIteration(++iteration);                     return;                 }                 else return;             }         }         finally {             this.color();         }     } }
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?
Set of discontinuity of monotone function is countable The result I am trying to prove is the following:     Let $F:\Bbb R\to\Bbb R$ be increasing. Then the set of points, at which it is discontinuous, is countable.   I have been reading this form Folland's Real Analysis and he proves this by considering the sum $\sum_{|x|&lt;N}[F(x^+)-F(x^-)]$ which has to be finite by some sort of telescoping sum. Now, I am not sure how he defines this sum. I am assuming he does this by using nets (let me know if there is another way to look at this), but he doesn't introduce the concept of nets until the next chapter. So I was looking for some other ways to prove this result and I found the following result (from Stein-Shakarchi) which is quite similar but assumes $F$ to be bounded.      A bounded increasing function $F$ on $[a,b]$ has at most countably many discontinuities.   This is shown by using the density of rationals in $\Bbb R$, i.e. $\exists r_x\in\Bbb Q$ s. t. $F(x^-)&lt;r_x&lt;F(x^+)$ corresponding to each point of discontinuity $x$.   Now I feel like there shouldn't be a problem in doing the exact same thing for unbounded increasing function. Is this right? Secondly how does this proof relate to the first one? I feel like there isn't much of a difference between the two proofs. To be precise I think that the previous sum is well defined/finite because of this countability of discontinuous points. What do you think about this way of thinking?  Edit. Here is the Folland's proof in more detail:  Since $F$ is increasing, the intervals $(F(x^-),F(x^+))$ are disjoint for all $\forall x\in\Bbb R$. Moreover,  $\forall|x| &lt; N$ such intervals are contained in $(F(-N),F(N^+))$ and so  $$\sum_{|x|&lt;N}[F(x^+)-F(x^-)] \leqslant F(N) - F(-N) &lt; \infty. $$ Hence the set $\{ x \in (-N,N) : F(x^+) \neq F(x^-)\}$ is countable. I was running out of space for Windows 10, so I deleted my Ubuntu partition and then combined the free space and added it to the Windows 10 partition into a single partition (the boot partition was untouched). Now all I get when I turn on my computer is:  Error no such partition. &gt;grub rescue   I have tried rebooting, but it did not work. Is there any way to fix it? My idea is that if i reinstalled Ubuntu it may fix it, but I'm not sure. I don't have a Windows repair disk, and I can't make one, but I do have a 4GB USB flash drive. Knowing $|z|$ and $|w|$ (and possibly $z\overline{w}$), what are $|z+w|^2$, $|zw|^2$, $|z-w|^2$, $|z/w|^2$? Question 1: Let $z$ and $w$ be complex numbers satisfying $|z| = 4$ and $|w| = 2$. Then enter in the numbers $$ |z+w|^2, |zw|^2, |z-w|^2, \left| \dfrac{z}{w} \right|^2 $$ below, in the order listed above. If any of these cannot be uniquely determined from the information given, enter in a question mark.  I plugged in $4$ and $2$ to each equation and got $36$, $64$, $4$, $4$, for question one. It was wrong.  Question 2: Let $z$ and $w$ be complex numbers satisfying $|z| = 5, |w| = 2,$ and $z\overline{w} = 6+8i.$ Then enter in the numbers $$ |z+w|^2, |zw|^2, |z-w|^2, \left| \dfrac{z}{w} \right|^2 $$ below, in the order listed above. If any of these cannot be uniquely determined from the information given, enter in a question mark.  I don't know how to even start on question 2 because of the $z\overline{w}$. EM algorithm gaussian mixtures- derivation I'm trying to make sense of a derivation I'm following from the lecture notes of Stanford's ML course.  Specifically the notes are here:   I'm particular I'm interested in the step where they are optimizing the lower bound of the log-likelihood by finding the derivative of that function w.r.t the mean (top of page 7). I'm a bit stuck on going from line 1 to line 2 in that sequence.  To copy here (using abbreviated notation for space):  $$ \nabla \mu_s \sum_{i=1}^{m}\sum_{j=1}^{k} w_j^{(i)}\log\frac{\alpha_j \exp\psi_{j}^{(i)}\phi_j}{w_j^{(i)}}  \qquad(1) $$ $$ \nabla \mu_s \sum_{i=1}^{m}\sum_{j=1}^{k} w_j^{(i)}\psi_{j}^{(i)}\qquad(2) $$ where $\psi_{j}^{(i)} =-\frac{1}{2}(x^{(i)}-\mu_j)^T\Sigma^{-1}_{j}(x^{(i)}-\mu_j)$ and $\alpha_j=\frac{1}{(2\pi)^{n/2}|\Sigma_j|^{1/2}}$.  The quantity $\mu_s$ is the mean (of a multivariate gaussian distribution) for class $s$.    In short, I'm not sure how they get from (1) to (2).  From just changing the log of (1) I see:  $$ \nabla \mu_s \sum_{i=1}^{m}\sum_{j=1}^{k} w_j^{(i)}\log \left(\alpha_j \exp\psi_{j}^{(i)}\phi_j\right) - w_j^{(i)}\log w_j^{(i)} \qquad(1) $$  To get to their form (2) my impression is that they take pre-emptively discard terms that would contain derivatives of $w_j^{(i)}$ (w.r.t. $\mu_s$).  At least if you assume that much, you get to (2).  However, as they show earlier in that PDF,  $$ w_j^{(i)} = p(z^{(i)}=j | x^{(i)}) =\frac{p(x^{(i)}|z^{(i)}=j)p(z^{(i)}=j) }{\sum_j p(x^{(i)},z^{(i)}=j) } $$ i.e. this quantity is the posterior distribution of the class labels.  Intuitively, it seems like $\partial w_j^{(i)}/ \partial \mu_s$ should be non-zero.  After all, changing the location of the mean $\mu_s$ would change your posterior probability for a particular class given the same data.  (Right?).  Just from a mechanical point of view, $\partial w_j^{(i)}/\partial \mu_j$ would seemingly have some non-zero terms since $p(x^{(i)}|z^{(i)}=j) \sim \mathcal{N}(\mu_j, \Sigma_j)$.  If I work through the algebra, I get  $$ \frac{\partial w_j^{(i)}}{\partial \mu_j} = w_j^{(i)}(1-w_j^{(i)})\frac{\partial \psi^{(i)}_{j}}{\partial \mu_j} $$  What am I missing here?  If I take the log-likelihood (without even thinking about EM algorithm),    $$ \ell = \sum_{i=1}^{m}\log \sum_{j=1}^{k}p(x^{(i)}|z^{(i)}=j)p(z^{(i)}=j) $$ and differentiate w.r.t $\mu_s$, I correctly get  $$ \mu_s^* = \frac{\sum_{i=1}^{m}w_s^{(i)}x^{(i)}}{\sum_{i=1}^{m}w_s^{(i)}} $$  so I'm comfortable with the eventual result, just not the intermediate steps. Set Theory: Tree Property Why does the tree property hold for regular cardinals but not singular cardinals? (I.e. There exists a tree of height $\kappa$ with countable levels and no cofinal branch for $\kappa$ a singular cardinal) How does commands like ls know what its stdout is?  It seems ls is operating different depending on what the target stdout is. For example if I do:  ls /home/matt/tmp    the result is:  a.txt b.txt c.txt   However if I do  ls /home/matt/tmp | cat   the result is (i.e. new line per result):  a.txt b.txt c.txt   The process is passed a file descriptor 1 for stdout right? How does it determine how to format the result? Does the file descriptor reveal information? Question about preposition -of- Sentence:      A set of deer antlers lying on a flat stone just inside [of?] one cave reveals more recent visitors.   Should we use preposition -of- in that case?  I have checked Corpus of Contemporary American English and have found examples of both usages:        ...to plant another 20 acres of vines, finish building the inside of   an on-site cave, and work on building a retail tasting room (Fiction)   However, opened and remained blue as the inside of an ice cave, paler   than the shell of a robin's egg (Fiction)   It looked like the wall on the inside of a cave: flat and kind of   scale (Fiction)   ...-To protect the inside of the cave. " // He stepped inside, leaving   the gate open.  (Fiction)     Views outside and inside of Wind Cave in South Dakota (Magazine)   Above, Black Hills grasslands and, right, boxwork inside of the cave   (Magazine)   You can see Bill Elliott's great photos of what you can see inside a   cave. (Spoken)   So, when I am asked, what was your feeling inside the cave? (Spoken)   At some point, we found a small river running through the inside the cave (Spoken)   We were gathered around a small fire inside the cave (Fiction)   About 700 feet inside El Sidrn cave, a research team including   Lalueza-Fox excavated 1,700 bones (Academy)      I still cannot come up with a clear pattern why we are using -of- in some cases but are not using it in other. Is it more a question of style rather then a grammar? Or it has something with how speaker/writer sees things around and perceives a reality? Does absence of -of- make things sound weird/wrong for native speaker? Thanks. In the cases of black holes that form from supernova and collapse of a massive star, I understand that in most of these cases, the star loses significant amounts of mass from the explosion. Presumably, after this point as the remaining mass becomes more dense as it further collapses unto itself, it eventually becomes a black hole with gravitational force greater than that of its parent star. But, if gravity is based on mass, how can the black hole have greater gravitational force than the star from which it is formed? what is beeping in my house? I know this sounds like a silly question and it may be closed before it may get a single answer but there is something strange in my house which beeps infrequently. I tried to troubleshoot the sound but no luck. I thought may be its coming from the living room but there is nothing special in the living room which may make a beep sound.  Can someone point me what should i look for to figure out what is making this sound? Different colors for different types of blocks in beamer How to get old Mapping and Voronoi nodes into Blender 2.82? I noticed that some nodes changed significantly with Blender 2.81 and 2.82. Now I can't follow older tutorials, because some have different options than me.   Voronoi Node is totally different Mapping Node is missing it's maximum / minimum clipping controls   Q: How to get these older nodes back into Blender 2.82? Haar Measure on Semidirect Product of Unimodular Groups Let $M, N$ be closed subgroups of a given locally compact topological group such that the product $P = MN$ is semidirect, with $M$ normalizing $N$.  Assume second countable, sigma compact, whatever so that Radon products coincide with product measures.  To make life easy, assume $M, N$ are unimodular.  How do we construct a Haar measure on $P$? Calculating the determinant gives $(a^2+b^2+c^2+d^2)^2$? I need to calculate the following determinant in order to prove the following equality:  $$\det\begin{pmatrix} a &amp; b &amp; c &amp; d \\ -b &amp; a &amp; -d &amp; c \\ -c &amp; d &amp; a &amp; -b \\ -d &amp; -c &amp; b &amp; a \end{pmatrix} = (a^2+b^2+c^2+d^2)^2.$$  I tried using Gauss-algorithm to get an easier matrix, but I'm not sure if I did it correctly.  Calling the $4$ lines $I$, $II$, $III$ and $IV$, I did:  (1) $II \cdot a$  (2) $III \cdot a$  (3) $IV \cdot a$  After this I did:  (4) $II' + I \cdot b$  (5) $III' + I \cdot c$  (6) $IV' + I \cdot d$  So finally I got the following matrix:  $$\begin{pmatrix} a &amp; b &amp; c &amp; d \\ 0 &amp; a^2+b^2 &amp; bc-ad &amp; ac+bd \\ 0 &amp; ad+bc &amp; a^2+c^2 &amp; cd-ab \\ 0 &amp; bd-ac &amp; ab-cd &amp; a^2+d^2 \end{pmatrix}.$$  I thought this would make the determinant a bit easier, unfortunately I must have done something wrong. Is multiplication with single lines allowed as I have done it?  Thank you very much. In a USB cable, is it OK to swap the D+ and D- wires? I heard that D+ and D- are differential signals, does it matter if I swap them when connecting a USB device to the computer? Why doesn't bash expand this variable when I prefix a command with a "one time variable assignment" If I run this bash command and prefix the statement, so that the variable fruit should exist, but only for the duration of this command:  $ fruit=apple echo $fruit  $   The result is an empty line. why?  To quote a comment from wildcard on :     parameter expansion is done by the shell, and the "fruit" variable is   not a shell variable; it's only an environment variable within the   environment of the "echo" command   An environment variable is still a variable, so surely this should still be available to the echo command? Why is the Yang–Mills existence and mass gap problem so fundamental? Ref:   Can anyone please explain why the Yang–Mills Existence and Mass Gap problem is so important / fundamental to contemporary mathematics (and, presumably, theoretical / mathematical physics)?  If possible, please include the following in your answer / response:  (1) Why the problem is so fundamental / important - for both mathematics and theoretical / mathematical physics; (2) How the solution to the problem would impact research in the above two fields; (3) (If applicable) What progress has been made so far in resolving it; (references to papers, books, other resources would be helpful).  I'm an upper-level undergraduate in theoretical physics, and so am seeking an answer / response at such level. How does two-weapon fighting work? I'm quite confused about attacking with two weapons in both hands and wondering what is required to be able to do to (in Pathfinder).  1. Base Attack Bonus Looking at the base attack bonus tables for different classes (e.g. the ) it seems like up to +5 you get only one attack per full action but starting from base-attack-bonus of +6 you get a second attack with +1.  2. Feats There is a feat . The existence of the feat sounds like you could not do two-weapon-fighting without it. However, in the description of "normal" it says:     If you wield a second weapon in your off hand, you can get one extra attack per round with that weapon. When fighting in this way you suffer a –6 penalty with your regular attack or attacks with your primary hand and a –10 penalty to the attack with your off hand. If your off-hand weapon is light, the penalties are reduced by 2 each.   3. Core Rulebook Chapter about combat If I understand the  it says that you need a full-round action do attack with both weapons in two hands.  So how do these things interact? Can I only attack with my off-hand weapon if my base-attack-bonus is high enough that I get second one with +1?  If not, how does the "multiple attacks from high base-attack-bonus" interact with dual-wielding? Assuming I reached a state of base-attack-bonus with +11/+6/+1 and have a full-round action to attack. Does that mean I can either attack with my primary weapon three times or use the primary weapon and off-hand weapon to attack only twice? Why would I then ever choose dual-wielding? Or can I attack three times with both weapons (leading to a total of 6 attacks with heavy malus) Or would I get 3 attacks with the primary weapon + 1 attack with the off-hand weapon? If so, what attack bonus do I have to use for each of the attacks? Java. Splitting a multiple word string into two word strings every space How do I convert the coordinates of a click to a tilemap position? How do you turn a tilemap (produced by TileD) for cocos2d where I can click on individual items and get a callback?  Is it just a case of converting captured touch and finding out where it is on the tilemap and then converting that to pixels  -- but that doesn't say what item was clicked on.  I have a tilemap of a city with buildings on it, and I'd like to be able to click or press on a specific building, get a callback.  What would be the best way to accomplish this? How can we communicate short messages long-distance? In our 5e game, we stole a boat. And a horse carriage. And a lot of other stuff for moving things between cities.   Our DM meant for this to be a way to skip road encounters. We decided to fund a shipping company and hire managers (Knights retainers, etc.) to turn a profit. The DM ruled that these would cover lifestyle expenses, provide us with easy smuggling, etc.   However, we want to keep tabs on the treasure we're moving back and forth.   What can we use for communicating with our managers from anywhere in the world? What about from say, across the city?  We don't need to communicate often or for long - a single round will work. All we need is for the manager to say "we need you back"