I realize this is a common error, and I have tried to solve it using the other questions asked about this exact error, however I could not come up with a solution. I made an array of 10 cars, and am setting the make, color, and year of each of them.  The getter and setter methods are in another class called "Car". I'm not sure where something is set to null.  Thank you in advance for any help.  Error: Exception in thread "main" java.lang.NullPointerException     at Main.main(Main.java:14)  import java.util.Random;  public class Main {  public static void main(String[] args) {      //Array of 10 cars     Car[] cars;     cars = new Car[10];      //Assign random colors and makes of my choice     cars[0].setMake("Toyota");     cars[1].setMake("Kia");     cars[2].setMake("Porsche");     cars[3].setMake("Ferrari");     cars[4].setMake("Honda");     cars[5].setMake("Jaguar");     cars[6].setMake("Lexus");     cars[7].setMake("Nissan");     cars[8].setMake("BMW");     cars[9].setMake("Tesla");      cars[0].setColor("Black");     cars[1].setColor("Green");     cars[2].setColor("Silver");     cars[3].setColor("Red");     cars[4].setColor("Yellow");     cars[5].setColor("White");     cars[6].setColor("Blue");     cars[7].setColor("Orange");     cars[8].setColor("Purple");     cars[9].setColor("Gold");      //Randomly selected years for the cars     int maxYear = 2015;     int minYear = 2010;     int maxYear2 = 2009;     int minYear2 = 1990;      Random r = new Random(1234);     cars[0].setYear(r.nextInt(maxYear - minYear + 1) + minYear);     cars[1].setYear(r.nextInt(maxYear - minYear + 1) + minYear);     cars[2].setYear(r.nextInt(maxYear - minYear + 1) + minYear);     cars[3].setYear(r.nextInt(maxYear - minYear + 1) + minYear);     cars[4].setYear(r.nextInt(maxYear - minYear + 1) + minYear);     cars[5].setYear(r.nextInt(maxYear2 - minYear2 + 1) + minYear2);     cars[6].setYear(r.nextInt(maxYear2 - minYear2 + 1) + minYear2);     cars[7].setYear(r.nextInt(maxYear2 - minYear2 + 1) + minYear2);     cars[8].setYear(r.nextInt(maxYear2 - minYear2 + 1) + minYear2);     cars[9].setYear(r.nextInt(maxYear2 - minYear2 + 1) + minYear2);  }  }
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?
What I am up to is to write some exercises dealing with logical formulas for my students, like:     And the students should draw these formulas on . At the end of the lesson, I really would like to print the correct answer for them. I found a great resource on a forum thread at , which helped me a lot to make up some Venn diagrams with tikz, but have some problems with visualizing complements, like ~A.  A simple, modified version of the TeX file found on the forum linked above, can be seen below, which produces the following expression:    \documentclass{letter}   \usepackage{tikz}   \def\firstcircle{(90:1.75cm) circle (2.5cm)}   \def\secondcircle{(210:1.75cm) circle (2.5cm)}   \def\thirdcircle{(330:1.75cm) circle (2.5cm)}   \begin{document}     \begin{tikzpicture}       \begin{scope}     \clip \secondcircle;     \fill[cyan] \thirdcircle;       \end{scope}       \begin{scope}     \clip \firstcircle;     \fill[cyan] \thirdcircle;       \end{scope}       \draw \firstcircle node[text=black,above] {$A$};       \draw \secondcircle node [text=black,below left] {$B$};       \draw \thirdcircle node [text=black,below right] {$C$};     \end{tikzpicture}   \end{document}   Which looks like:    Could anyone please help me out plotting/defining some expressions dealing with complements? A nice example could be:    That should look like: (image from )    I do not insist on the red color :)  I would like to use the simplest possible solution, as I would like to mass generate the exercises with the help of . So any suggestion dealing with gnuplot, R or any other opensource packages is welcome. Thank you!    UPDATE (25/01/2011): added details based on answers.  Thank you @Leo Liu, you helped me a lot! I modified a bit the code you suggested to be able to color the area outside of the two circles also (in the H universe), but have no idea how to set a background to that polygon also. The code:  \begin{tikzpicture}[fill=gray] % left hand \scope \clip (-2,-2) rectangle (2,2)       (1,0) circle (1); \fill (0,0) circle (1); \endscope % right hand \scope \clip (-2,-2) rectangle (2,2)       (0,0) circle (1); \fill (1,0) circle (1); \endscope % outline \draw (0,0) circle (1) (0,1)  node [text=black,above] {$A$}       (1,0) circle (1) (1,1)  node [text=black,above] {$B$}       (-2,-2) rectangle (3,2) node [text=black,above] {$H$}; \end{tikzpicture}   And the image generated:    I will also look for even odd rule in the near future which does not make sense for me at the moment but looks really simple and promising! Which arena do free and crown chests use when determining the cards you will get? Is a quotient group a subgroup? Is a quotient group a subgroup?   I am trying to solve the question below, and if the answer to above is "yes," then my proof will follow below.   I am trying to prove that a cyclic group G, has a cyclic quotient group G/N.  Where N is a normal subgroup.  A SUBGROUP OF A CYCLIC GROUP IS CYCLIC.  By   So if   (1) G is cyclic   (2) G/N is a subgroup   (3) G/N is a cyclic subgroup   (4) The Quotient group G/N is cyclic   I am unsure about my reasoning in step (2), Is this a valid assumption? Is there a way to closely approximate the CDF of a student-t distribution at a point $x$ without involving the hypergeometric function? For example, by using a series expansion, or expressing the CDF in terms of simpler functions?  The t-distribution can   $$t = \frac{X\sqrt{n}}{Y}$$  where $X$ is normally distributed with mean 0 and variance $\sigma^2$; $\frac{Y^2}{\sigma^2}$ has a chi-squared distribution. Maybe this expression can help simplify the t CDF?  I am trying to write an algorithm to compute the student-t CDF for any real number, so using the hypergeometric function will be extremely difficult. I am also trying to avoid integrating the PDF to get the CDF. I have customer data from 2 brands. The data structure are the same, but I expected the customer behaviour to be different in different brand.  So I could train 2 models, 1 for each brand, or I could train one model on both brands, but flag which brand the customers belongs to within the data.  So my question is, would training on both brands with flags be too much more work for the Machine Learning (I'm using neural network), and therefore be harder to achieve good accuracy than to have dedicated models for each brand? $f$ be an analytic function defined on $\mathbb{D}=\{z\in\mathbb{C}:|z|<1\}$ I came across the following problem that says:  Let $f$ be an analytic function defined on $\mathbb{D}=\{z\in\mathbb{C}:|z|&lt;1\}$ such that the range of $f$ is contained in the set $\mathbb{C}\setminus (-\infty,0]$. Then  $f$ is necessarily a constant function. there exists an analytic function $g$ on $\mathbb{D}$ such that $g(x)$ is a square root of $f(z)$ for each $z\in\mathbb{D}$. there exists an analytic function $g$ on $\mathbb{D}$ such that $\operatorname{Re}g(z)\geq 0$ and $g(z)$ is a square root of $f(z)$ for each $z\in\mathbb{D}$. there exists an analytic function $g$ on $\mathbb{D}$ such that $\operatorname{Re}g(z)\leq 0$ and $g(z)$ is a square root of $f(z)$ for each $z\in\mathbb{D}$.   I have to determine which options are correct. Can someone help in the right direction? Thanks in advance for your time. How can something happen when time does not exist? I saw  hosted by Stephen Hawkins.  And if I didn't get it wrong, it says that there was no time before the big bang, time was created there.  So how can anything happen when there is no time (eg: the creation of time and the universe)? Is this what he calls a 'singularity'? Which I could think like this: when there is no time nothing can happen, except during this singularity.  Of course I don't know of a law that says 'when there is no time nothing can happen..', I just came up with it, as something intuitive. What is the geometric meaning of the determinant of a matrix? I know that "The determinant of a matrix represents the area of ​​a rectangle." Perhaps this phrase is imprecise, but I would like to know something more, please.  Thank you very much. What does "xmlns" in XML mean? A matrix inside a table Possible Duplicate:          I am trying to insert a matrix inside a table, and I am looking for a good way to do this. Usually when I write matrices in equations, I use array environment, so I naively defined an array inside tabular, and it sort of works. The only problem is that the matrix itself seems to take up a huge amount of space inside the cell. An example is   \begin{tabular}{|c|c|} \hline \textbf{EKF} &amp; \textbf{UKF}\\ \hline $Q = \left[ \begin{array}{cc} 0.1 &amp; 0 \\ 0 &amp; 0.1 \end{array}\right]$ &amp; $Q = left[ \begin{array}{cc} 0.01 &amp; 0 \\ 0 &amp; 0.01  \end{array}\right]$\\ \hline $R = 5 \times 10^{-3}$ &amp; $R = 5 \times 10^{-5}$ \\ \hline \end{tabular}   Is there any way to increase the spacing in the cell containing the matrix without that matrix taking up all the space? Using swap space instead of RAM can drastically slow down a PC.  So why, when I have more than enough RAM available, does my Linux system (Arch) use the swap?  Checkout my conky output below:    Also, could this be the cause of speed and system-responsiveness issues I'm having?  Output of free -m :  $ free -m              total       used       free     shared    buffers     cached Mem:          1257       1004        252          0         51        778 -/+ buffers/cache:        174       1082 Swap:          502        144        357 Are there any other words similar to these words:  Award, Bestow, Donate, Grant, Give, Provide, Tax  ...that give a meaning of:  I freely give to you a portion what I have acquired or earned, without hesitation or expectation of anything in return. You are owed this, without question. There is no emotion involved with this transaction. It just is what it is.  For example: as a member of the Thief's Guild, 20% of everything you acquire will be ______ to the Guild.  Bestowed and Granted are very close...  Any other ideas? Physical meaning of this integral in $k$-space I am trying to solve an integral in $k$-space where I want to calculate the ratio of the average energy of an arbitrary electronic band ($E(k)=k^n)$ to the square of average group velocity of electrons($v_g   = k^{n-1})$ approximately in the form of this expression given by $$L=\frac{\frac{\sum_{\mathbf{k}}k^{n}}{\sum_{\mathbf{k}}1}}{\left(\frac{\sum_{\mathbf{k}}k^{n-1}}{\sum_{\mathbf{k}}1}\right)^2}\;.$$  Now, I want to do this for $d$-dimensions, so I convert this sum to integral.  $$L=\frac{\dfrac{\int_{0}^{k_f}k^{n} d^d k}{\int_{0}^{k_f}1d^d k}}{\left(\dfrac{\int_{0}^{k_f}k^{n-1}d^d k}{\int_{0}^{k_f}1d^d k}\right)^2}$$ where $d^dk  = \dfrac{d \pi^{d/2}}{\Gamma(\frac{d}{2}+1)}k^{d-1}dk$ is the volume element in $d$-dimensional space.  I want to get a simple expression for $L$ and how it depends with $k_f,n$ and $d$. any physical insight into this integral could also be helpful. I have named him/he who shall not be named. Which of these is correct? I think it should be "him" because "him" is a direct object in this context. In this context, "him/he who shall not be named" is not a proper noun. Automatically turn on VPN on computer unlock Ubuntu 18.04 When I wake the laptop from the sleep I need to get the VPN state as I left it (turned on). Can't find the setting of autoconnect in VPN settings... Need some easy way to ask the system to autoconnect the VPN when the internet is available.  Edit based on comments:  Ubuntu 18.04 has no option to Always connect to VPN when using using this connection. Questions on perfect squares I recently attended a test which ask me two question based on perfect squares; here they are:  $1.$ How many even perfect squares between $1000$ and $5000$ are divisible by both $5$ and $9$?  $2.$ Can there be a perfect square whose digits consists of exactly $4$ ones, $4$ twos and $4$ zeroes in any order?  I haven't done anything much on perfect squares so I was reluctant to attempt them during exams, although as I had some spare time after finishing the other questions, I tried thinking about the first problem and I noticed that only $3600$ seems to satisfy the conditions, which is correct, but I don't know how to get this mathematically? And for the second problem, I don't have any clue till now.  Unfortunately they haven't given me any solutions for the questions, nor any ideas as to how to solve them (mathematically)? I installed an Ubuntu alpha or beta and have been keeping it up to date.   So, Should I presume that my system has automatically updated to the next alpha or beta, and will be running the official release when it's finished? Will having multiple domains improve my seo? How would you go about proving that $$\gcd \left(\frac{a}{\gcd (a,b)},\frac{b}{\gcd (a,b)}\right)=1$$  for any two integers $a$ and $b$?  Intuitively it is true because when you divide $a$ and $b$ by $\gcd(a,b)$ you cancel out any common factors between them resulting in them becoming coprime. However, how would you prove this rigorously and mathematically? I would like to compare the contents of a couple of collections in my Equals method.  I have a Dictionary and an IList.  Is there a built-in method to do this?  Edited: I want to compare two Dictionaries and two ILists, so I think what equality means is clear - if the two dictionaries contain the same keys mapped to the same values, then they're equal.