(Java) Why does this constructor cause a null pointer exception? I'm trying to make a matrix using two dimensional arrays, but when I try to print it to the screen I get a null pointer exception  import java.util.concurrent.ThreadLocalRandom;  public class GridWorld {   // data    int [][] grid; // a "r by c" grid will all entries of type int   int r; // no. of rows    int c; // no. of cols    final static int ROW = 4;  // Default row size    final static int COL = 4;  // Default col size    // constructors    // 1. default constructor: construct a 4x4 Grid of int   //    the entry at row i and col j is  4*i+j+1    public GridWorld() {     r=4;     c=4;     for(int i =0;i&lt;r;i++){       for(int j=0; j&lt;c; j++){         grid[i][j] = 4*i+j+1;}}    }    * -----------------------------      |    1 |    2 |    3 |    4 |      -----------------------------      |    5 |    6 |    7 |    8 |      -----------------------------      |    9 |   10 |   11 |   12 |      -----------------------------      |   13 |   14 |   15 |   16 |      -----------------------------   */  public void display() {    System.out.println("-----------------------------");    for(int i=0;i&lt;this.r;i++){      for(int j =0;j&lt;this.c;j++){        System.out.print("|    "+this.getVal(i,j)+" ");}      System.out.println(" |");      System.out.println("-----------------------------");}   }      GridWorld grid1 = new GridWorld();      grid1.display(); }     I was hoping this would print something similar to the commented picture, but instead it is giving me java.lang.NullPointerException  I'm pretty new to java and couldn't find how to fix this anywhere, any help would be greatly appreciated.
What is a NullPointerException, and how do I fix it? 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?
Keep box-shadow direction consistent while rotating Are there any method to extend a filesystem when i adding more hdd to it without using LVM? What are those ? I was working on a worksheet for class and came across this problem:      Let $\varphi:R\to S$ be an onto ring homomorphism with the property that every ideal of $R$ is principal. Show that the same must be true for $S$.    I honestly do not know how to do this one! Orthogonal Projection of $ z $ onto the Affine set $ \left\{ x \mid A x = b \right\} $ Until recently  had one single reputation point, you can see it in this old screenshot:    Now it has over 2K reputation all of a sudden.. what has caused this? Has it affected "real" members as well? Let $P$ denote the quotient space obtained by the action of $\mathbb{Z}\backslash2\mathbb{Z}$ by the antipodal map $z\mapsto\frac{1}{z}$ on the riemann sphere $\hat{\mathbb{C}}$ (identified here with $\mathbb{C}\cup\left\{\infty\right\}$). I identify $P$ with the set:  $\left\{ z\in\mathbb{C}:\left|z\right|&lt;1\right\} \cup\left\{ e^{it}:0\leq t\leq\pi\right\} $   that is to say, I use elements of the above set as the representatives for the equivalence classes in $P$. I am looking for formula for a function $f:P\times P\rightarrow[0,\infty)$ such that $f$ is a metric on $P$. Specifically, I would like a formula for $f$ that I can evaluate by plugging in representative elements in the above set (or something like that, more or less).  Thanks in advance.  Edit: forgive me for sounding desperate, but I cannot make due with an explanation of how to obtain such a formula. I want the formula.   An analogy for you if I have yet to make myself clear: suppose I was asking for the area of a square with side length $s$. The answers I have received so far for my question are akin to saying "multiply $s$ by itself" or "use the area formula for a square". The answer I am looking for is akin to saying "$s^{2}$". I need the formula. And please, no expressions with differentials, nor matrices, or any of that. I need to know how to compute the metric by using the complex numbers in the indicated set that I have identified with $P$. Notification for reviews shows way too many Git ignore file for Xcode projects Which files should I include in .gitignore when using Git in conjunction with Xcode? Why does QgsSpatialIndex.nearestNeighbor(point, 1) sometimes return 2 lines? Javascript add js libraries by code I would like to know where to find the source code of Ubuntu. I'd like to see how far it is "open source". I've seen papers (e.g., in Science) where the first two authors are listed in non-alphabetical order, and yet there are asterisks behind their names to say that they contributed equally.   It seems strange to me, because if the two authors are in alphabetical order, then it could be that the first author contributed more or the two contributed equally, and this can be made clear with asterisks in the paper if it's the latter case. When they're in non-alphabetical order, however, if someone only sees the author list without seeing the paper, he/she will likely assume that the first author contributed most.  So my question is: Are there particular reasons why people do that? (This  is related, but I don't think the answers there get to my question.) Why don't elves have more babies? Proving that two vector spaces of equal dimension are isomorphic Given the following problem     Let $U$ and $V$ be finite dimensional vector spaces, such that $\dim(U) = \dim(V)$. Prove that $U$ and $V$ are isomorphic.   I was just wondering if somebody could critique and validate my proof.  Proof  Two vector spaces $U$ and $V$ are isomorphic if and only if there exists a bijection $\phi: U \to V$. That is, an invertible linear map between the two. Let $\dim(U) = \dim(V) = n$ and let $\left\{u_1, \dots, u_n\right\}$ and $\left\{v_1, \dots, v_n\right\}$ be bases for $U$ and $V$, respectively. It follows that any vector $u \in U$ can be written as  $$ u = c_1u_1 + \cdots + c_nu_n $$  We define $\phi: U \to V$ as  $$ \phi(c_1u_1 + \cdots + c_nu_n) = c_1v_1 + \cdots + c_nv_n $$  Observe that $\phi$ is invertible. That is, given a vector  $$ v = d_1v_1 + \cdots + d_nv_n $$  in $V$, we define $\phi^{-1}: V \to U$ as  $$ \phi^{-1}(d_1v_1 + \cdots + d_nv_n) = d_1u_1 + \cdots + d_nu_n $$  Since there exists a bijection between $U$ and $V$, they are isomorphic. Spaces in files names in \input or \includegraphics Find all number $n\in \mathbb N$ such that $\varphi (n)=14$ Is colour, as represented using primary colours, accurate only to humans? Slightly biological, hopefully physical enough to be answered.  Suppose a magenta hue is represented by a mix of red and blue pigment. This is all very well for a creature with red and blue photoreceptors, but suppose it was seen by a creature which had a magenta-sensitive receptor, but no red or blue. Would the colour appear the same (insomuch as a qualititave concept can appear the same, I suppose I mean 'Would they interpret it as colour of the same wavelength?')?  The crux of my question is, do the particular bands in which photoreceptors are activated affect vision of additive, as opposed to pure, hues?  Finally, completely off-topic, but if there happens to be a biologist around, do animals on the whole have similar photoreceptors, or are they placed largely randomly?  Thanks, Wyatt Is CAT5 cable good enough for RS-485 vs "true" RS-485 cable How do the Goodman-Kruskal gamma and the Kendall tau or Spearman rho correlations compare? In my work, we are comparing predicted rankings versus true rankings for some sets of data. Up until recently, we've been using Kendall-Tau alone. A group working on a similar project suggested we try to use the  instead, and that they preferred it. I was wondering what the differences between the different rank correlation algorithms were.  The best I've found was , which claims Spearman is used in place of usual linear correlations, and that Kendall-Tau is less direct and more closely resembles Goodman-Kruskal Gamma. The data I'm working with doesn't seem to have any obvious linear correlations, and the data is heavily skewed and non-normal.  Also, Spearman generally reports higher correlation than Kendall-Tau for our data, and I was wondering what that says about the data specifically. I'm not a statistician, so some of the papers I'm reading on these things just seem like jargon to me, sorry. How do I create a line graph which ignores zero values? I want to create a graph showing trends over time, calculated from a formula of various data.  However, some data is missing, resulting in zeroes in the calculated data which the chart uses.  When plotting this data against as a line graph, it's drawing a line down to the axis, which I don't want.  I'd like either a gap in the line, or skip the data point and draw from directly previous to next.  i.e. given this data:  00.0    61.6    39.5    74.6    86.8    72.0    66.5    99.5    85.6    80.6    95.0    122.4 81.0    83.1    88.2    00.0    94.3    60.5    00.0    99.5    95.8    86.2    00.0    111.4 84.1    110.8   78.9    62.0    75.9    102.2   89.9    87.1    81.6    73.5    00.0    116.9   All the 00.0 items mean "no data", so I'd like them ignored (not treated as 0 value).   This is the chart I currently have:   This is how I'd like the chart to come out:   Again, I don't mind if the dotted lines are blank or solid, so long as they don't go down to zero.  The data is dynamic/calculated, so I can't just say =AVERAGE(prev,next) since I don't know where missing data will occur in advance - I need a solution which takes this into account.  Any ideas?