I'm writing this code where I'm calling a method to act on an element in an array of objects, and to do this I first need to check if the element is null. I am doing this using if(array[x][y]!=null), but I get a NPE pointing to this line and I don't understand why.  Here's the code in question:  Method to check:      public void addPiece(Piece p, int x, int y){//Method to add a piece to a given space on the board      if(gboard[x][y]!=null)//Check to see if space is empty before adding piece          System.out.println("Error: Board space already occupied. Please choose another space.");      else{          gboard[x][y]=p;          gboard[x][y].setXpos(x);          gboard[x][y].setYpos(y);      } }           Main method where it is being called:      public class PracticeMoves {//Demo method  public static void main(String[] args) {       Scanner kb=new Scanner(System.in);      Board board=new Board();      Piece p1=new Piece("Droid","Blue", 0, 0);      board.addPiece(p1,3,5);   Class where gboard is created:      public class Board {  private Piece[][] gboard;//initialize a 2D array of Piece objects to form the gameboard  public Board() {//no-args constructor to initialize gboard      Piece[][] gboard=new Piece[8][8];    }   Class for the piece object:      public class Piece {//abstract class that the rest of the pieces inherit from private String name; private String colour; private int xpos; private int ypos; public Piece(String n, String c, int x, int y){     name=n;     colour=c;     xpos=x;     ypos=y; } public String getName() {//getter and setter methods     return name; } public void setName(String name) {     this.name = name; } public String getColour() {     return colour; } public void setColour(String colour) {     this.colour = colour; } public int getXpos() {     return xpos; } public void setXpos(int xpos) {     this.xpos = xpos; } public int getYpos() {     return ypos; } public void setYpos(int ypos) {     this.ypos = ypos; } public String toString() {//toString method     return name+colour; }   }  Any help would be much appreciated. If there is any other part of the code you might need to see please let me know.  Thanks.  EDIT: Since this is being marked as a duplicate, I want to point out the the question I was referred to is asking what a NPE is. I know what it is, and I'm posting this here because I have no idea why one should appear here. Every question I can find similar to this is, the answers say that there shouldn't be an NPE and when they run it themselves no such error is detected. I just want to find out why I am getting this error, as it seems like there should be no reason for 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?
How do I prevent yum from updating a particular RPM? For certain reasons I have to keep a slightly older version of a particular RPM installed on my box (Fedora 11). The problem is that every time I do a package update yum (or one of its GUI equivalents) wants to update this RPM to the latest version, which is annoying - especially when I update it by mistake.  Is there a way to 'pin' this version so that yum knows to never try and update it? I love apples. I like to eat them with skin as it has plenty of fiber in the skin. But apples are famous for wax and pesticides on the skin which I don’t want to ingest. I have read many articles on the web and suggestions for removing the wax from the surface.   These suggestions include soaking in vinegar or hot water and other methods. They suggest that soaking apples in vinegar removes the wax that can be seen in the vinegar. I have done that, but never seen any residue of wax in the vinegar.   So I have set aside a new kitchen sink Scotch-Brite scrubber for this purpose and been scrubbing the apple skin under running water before eating. I think this method should remove most of the wax and pesticides. I would like to hear your input. Differences between longtable and xtab I have a pretty simple table that needs to span multiple pages. This seems like a job for either the / package or the  package.   The voting on the answers to this  suggest that longtable is the preferred package, yet xtab is much newer and has been revised since that question was asked.  What are the differences between xtab and longtable and when is one preferable to the other? On a similar note: when using Gauss' Law, do you even begin with Coulomb's law, or does one take it as given that flux is the surface integral of the Electric field in the direction of the normal to the surface at a point? 17.10 Super key to open applications system wide keyboard hook on X under linux Simple past or past perfect with "by" and years What is the difference between      He became a star by 1990's.     He had become a star by 1990's.    Is the first sentence correct? If yes, then please tell me the difference between the two. How to pass a list of columns to data.table where some are predetermined Display Top X results for each unique value I am trying to figure out how I can output any machine that has had the latest 3 backups be larger than 10GB. My SQL Table looks similar to the below table:  ComputerID | BackupImageName | WindowsVolumeGUID | FileSize | TimeCreated 1234       | PCBackup.spi    | kjsdfai-dadad-ddd | 10400    | 05-22-20 1234       | PCBackup1.spi   | kjsdfai-dadad-ddd | 10500    | 05-23-20 1234       | PCBackup2.spi   | kjsdfai-dadad-ddd | 10300    | 05-24-20 1234       | PCBackup3.spi   | kjsdfai-dadad-ddd | 10900    | 05-25-20 1225       | PCBackup4.spi   | kjsdfa5-dadad-ddd | 10600    | 05-22-20 1225       | PCBackup5.spi   | kjsdfa5-dadad-ddd | 5000     | 05-23-20 1225       | PCBackup6.spi   | kjsdfa5-dadad-ddd | 10000    | 05-24-20 1225       | PCBackup7.spi   | kjsdfa5-dadad-ddd | 4588     | 05-25-20   I need to output all machines (computerID's) or Volumes (WindowsVolumeGUID) that have their latest 3 files in the list greater than 10000 file size. So from the above table it would output the computerID of 1234 because its latest 3 are greater than 10000 file size and even though the computerID 1225 has 2 files greater than 10000 it would not output the result because there is a break in-between the two large files. The search will need to take into account the WindowsVolumeGUID since some machines have more than one volume and I need to take into account the individual volume backups and count the latest entries based on that.  Alternatively, I can also accomplish the same thing if there is a way to output the top 3 results for each unique WindowsVolumeGUID and not just across the board.   Any help would be greatly appreciated! Filezilla or WinSCP save password in plain text which is unsecured on public machines. Is there any FTP client can save and encrypt password so that people using it only can access to FTP but not able to see password? Thanks! How to setup Squid Proxy (for localhost services and Tor and I2P) The title kind of says it all. Is it possible to replace C# with C++ on a game using Unity? How can I check dependency list for a deb package How can I check dependency list for a deb package. I am running Ubuntu 11.10 and I have backed up all deb packages from var/cache/apt/archives. I want to format my pc and re-install selected applications only. Also how can I get the list of installed packages and dependencies. Do I have to pay taxes in the US if my online store sells to US customers even though I don't live in the US? I  own a website and I sell digital content. I'm a nonresident alien with the US. Most of my customers are US based so I was wondering will I have to pay any taxes to the US?  I have read that      For nonresidents, taxable income is separated into two categories:         Income that is effectively connected with a U.S. trade or business, after the deductions that are allowed, is subject to U.S. income tax   at graduated rates - the same rates that apply to U.S. citizens and   residents - or lower rates if the provisions of a tax treaty apply.   Income that is subject to U.S. income tax, for being U.S. source income, but that is not effectively connected with a U.S. trade or   business, is subject to a flat 30% tax      Is this true and do I belong to any of these categories?  If I form an LLC or C corp am I liable for this withholding tax?  My customers are based in the US and I believe all income is considered FDAP income according to the IRS:     Fixed, Determinable, Annual, or Periodical (FDAP) income is all   income, except:         Gains derived from the sale of real or personal property (including market discount and option premiums, but not including original issue   discount)   Items of income excluded from gross income, without regard to the U.S. or foreign status of the owner of the income, such as tax-exempt   municipal bond interest and qualified scholarship income      The thing is the IRS also says:     Effectively Connected Income, after allowable deductions, is taxed at   graduated rates. These are the same rates that apply to U.S. citizens   and residents. FDAP income generally consists of passive investment   income; however, in theory, it could consist of almost any sort of   income. FDAP income is taxed at a flat 30 percent (or lower treaty   rate) and no deductions are allowed against such income. Effectively   Connected Income should be reported on page one of Form 1040NR. FDAP   income should be reported on page four of Form 1040NR.   In the last quote, it’s like they say it only applies to passive income but if they feel like it, they can apply this to all income?? Is it: My apples and orange are/is wrong? Simple question:     My apples and orange are wrong   or     My apples and orange is wrong   I am not a native English speaker, and I am having some trouble choosing between plural are or singular is for that kind of example. Will something accelerate forever if a constant force is applied to it on a frictionless surface? If so how? I don't understand the fact that let's say hypothetically I was pushing a block on a frictionless surface, and I kept applying the same force on the object how it would keep accelerating! Wouldn't there have to be a certain velocity where it would stop getting faster? If not then what is actually acting on the object to cause it to accelerate infinitely? Which command should I use for textual subscripts in math mode? Textual subscripts like in W_{total} should be typeset in an upright text font (so that code isn't good practice), as has been  in   . Now there are several ways to achieve this, and I'm somewhat confused which I should use:   W_{\rm total} is nice and short, and appears to work in all circumstances, but I expect LaTeX people will frown upon it :-) Is there any good reason against this? W_{\mathrm{total}} &ndash; is this the LaTeX equivalent of the \rm approach? W_{\textnormal{total}}  as total is text and not math&nbsp;... In , Ulrike Fischer suggests a more complicated approach. Even W_{\operatorname{total}} appears to work, but it seems inappropriate.   Note: I always assume here that amsmath is loaded.  I've already asked some questions above, but my main question is: which of these options is the best practice for textual subscripts?    Let me point out why I haven't mentioned \text, \textrm or \textup above. Those commands (mostly) keep the font of the context they're used in, e.g., in an italic context, \text and \textrm would give italic subscripts, and all three yield bold subscripts in a bold context.  Final note: This question is similar to, but not the same as all those  about the  between , , , ,  that have been asked before. Maybe it's still a duplicate&nbsp;... How do I run a sudo command in Emacs? Headers of \chapters* take the headers of their previous \chapter When using book.cls and using \chapter* after a \chapter, the header used in \chapter* is wrong. An example is pasted below.   Is there any known workaround for that? I have tried quite some tricks without success.   \documentclass[]{book}  \begin{document}  \chapter{First Chapter} aslkjdf  \chapter*{Unnumbered Chapter} The GNU General Public License is a free, copyleft license for software and other kinds of works.  The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.  When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.  To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.  For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.  Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.  For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.  Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.  Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.  The precise terms and conditions for copying, distribution and modification follow.  \end{document} I'm not sure how to prove these basic theorems in propositional calculus. Instead of using the standard axioms, we're supposed to use:   Deduction Theorem (if $\Phi, \alpha \vdash \beta$ then $\Phi \vdash \alpha \to \beta$),  Reductio (if $\Phi, \alpha \vdash \, $, then $\Phi \vdash \lnot \alpha$), Cut Rule (if $\Phi \vdash \alpha$ and $\Psi, \alpha \vdash \beta$ then $\Phi \cup \Psi \vdash \beta$),  Inconsistency Effect (if $\Phi \vdash \, $, then $\Phi \vdash \beta$ for every formula $\beta$), and  the Principle of Indirect Proof (if $\Phi, \lnot \alpha \vdash \, $, then $\Phi \vdash \alpha$),    as all the axioms can be deduced using these theorems.  I don't really know how to start the proofs without using the axioms:  i) prove that $\lnot(\alpha \to \beta) ⊢ \alpha$  ii) prove that $\lnot\alpha \vdash \alpha \to \beta$  Any suggestions on how to start these proofs or any insight at all would be greatly appreciated!  Thanks!