I am implementing a binary search tree in java, writing the methods recursively. I did the insert methods, and now I am stuck on the first traversal method, the in order one. When I call it in my test code, after adding a few elements, (tree.inorderTraversal), I get a null pointer exception at the rescursive in order method, and I don't see why. Could it be something wrong with the insert method?   public void insertInBinaryTree(E newItem) {     BinaryTreeNode&lt;E&gt; node = new BinaryTreeNode&lt;E&gt;(newItem);     if (root == null) {         root = node;     } else {         insert(root, newItem);       } }  // Recursively insert a node containing newItem into a non-empty tree. Used // by insertInBinaryTree private void insert(BinaryTreeNode&lt;E&gt; treeNode, E newItem) {     if (newItem.compareTo(treeNode.getItem()) &lt; 0) {         if (treeNode.getLeftChild() != null) {             insert(treeNode.getLeftChild(), newItem);         }         else {             treeNode.setLeftChild(new BinaryTreeNode&lt;E&gt;(newItem));         }     }     else {         if (treeNode.getRightChild() != null) {             insert(treeNode.getRightChild(), newItem);         }         else {             treeNode.setRightChild(new BinaryTreeNode&lt;E&gt;(newItem));         }     } }  // If the tree is not empty, initiates an inorder traversal. This should // print all items in ascending order. If the tree is empty, just prints // "Tree is empty" public void inorderTraversal() {     System.out.println("\nInorder Traversal");      if (root == null) {         System.out.println("Tree is empty");     } else {             inorder(root);     }   }  // Recursive inorder traversal of a non-empty tree. Used by // inorderTraversal. private void inorder(BinaryTreeNode&lt;E&gt; treeNode) {     inorder(treeNode.getLeftChild());     System.out.print(treeNode.getItem());     inorder(treeNode.getRightChild()); }
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?
Java and manually executing finalize Using competitors domain with different ending to boost traffic Community user id interpreted by absolute value in search How to wrap lines in a jtable cell? how to prove an element is non-zero in a tensor-product I was studying the following example from Atiyah &amp; MacDonald's Introduction to Commutative Algebra:   Let $x$ be the non-zero element in $N := \mathbf{Z}/ 2\mathbf{Z}$, $M := \mathbf{Z}$, and $M' := 2 \mathbf{Z}$. The element $2 \otimes x$ is zero in $M \otimes N$, but non-zero in $M' \otimes N$. I suppose this can be seen by the fact that $2 \otimes x$ generates $M' \otimes N$, and the tensor-product $M' \otimes N$ is non-zero.   However, I was wondering, what one would do if that element weren't a generator of $M' \otimes N$. So my question is:   What are the methods to prove that an element is non-zero in a tensor-product of modules?   Thanks a lot! Introductory biology text for an outsider I'm a maths major and I have an interest in learning biology. I know very, very little; I know how babies are made and that's about it. Could anyone recommend a stimulating text to read for its own sake and also to use to learn biology? Writing to NTFS drive in Linux I've got an external USB drive that is formatted with NTFS mounted on ~/tmp.  I can read it just fine, but cannot write to it, even as root (temp is a folder on the USB drive):  [root@Plugbox temp]# touch test touch: cannot touch `test': Permission denied [root@Plugbox temp]#   However, if I do a cat /proc/mounts, it looks like I do have NTFS read/write support:  [root@Plugbox temp]# grep /dev/sdb1 /proc/mounts /dev/sdb1 /root/tmp ntfs rw,relatime,uid=0,gid=100,umask=02,nls=utf8,errors=continue,mft_zone_multiplier=1 0 0 [root@Plugbox temp]#   Finally, if I go to the folder above temp, it looks like I should have plenty of permissions to write to the folder:  [root@Plugbox tmp]# ls -al total 61500764 ... drwxrwxr-x 1 root users           0 Apr 19  2010 temp ... [root@Plugbox tmp]#   What am I missing? I am trying to perform stepwise regression for variable selection in R.  In matlab, the stepwisefit function is able to work in n &lt; p problems. Trying to use step() for such problems i get the error message AIC is -infinity for this model, so 'step' cannot proceed. Is there a way to modify parameters so i can use step function? English idiom for 'bad consequences stemming from too much ambition' I'm looking for an idiom that is equivalent to the Portuguese:  Quem tudo quer, tudo perde. Who wants everything, loses everything.  It basically points out that being too ambitious will have bad consequences: not only does one not get what one's striving for, but one also ends up losing what one already had (and probably took for granted). This idiom should be usable in everyday speech. Limit of the sequence $a_n=\sqrt[n+1]{(n+1)!}-\sqrt[n]{n!}$ I can't write Chinese characters in edited posts, but OP could when posting I want to writing the matrix on the arrow from X to Y 3x3 type, from Z to Y 3x2 type ; Good textbooks on homological algebra Can screen layouts or workspaces be locked? Does $x^2 - y^2 = 12345678$ (x,y are integers) have any solutions? This question appeared in KVPY online exam held on Nov 5. This equation is the equation of a hyperbola so any solution must be of the form $a\sec(k),a\tan(k)$. So no solutions. 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. Why is there a white space on the left side?  \documentclass{standalone} \usepackage{asymptote} \begin{document} \noindent \begin{asy} size(10cm,10cm); draw((0,0)--(100,100)); draw((0,100)--(100,0)); dot((50,50)); \end{asy} \end{document} Framing a question whose answer is an ordinal number I am the third daughter (or son) of my parents.   OR      How should a question that is answered with the above sentences be framed? How do I get started with 'painting with light' photography? Tunnels being naturally dark may not be the most intuitive choice for a place to take pictures. But I love the '' work that artists such as '' are putting out and they're clearly seeking out places like tunnels, caves, garages... Dark places in other words, to create their works of art. Which brings two questions to mind:   How do I go about finding places that I can accomplish this sort of 'tunnel photography.' What are some techniques that I can use to 'paint with light' in my photography once I have found some locations? What is this yellow and white mass inside my red cabbage?