Null pointer exception in setting font in Java I am encountering some issue while trying to set font for drawing string function in Java. My goal is to draw something on image using function drawString(text, posLeft, posTop); where text is the string, and posLeft and posTop are positions of it from left and top of the screen. In that purpose i have following code:          Icon icon = new ImageIcon(image);                             image.getGraphics().setFont(new Font(&quot;Arial&quot;, Font.BOLD, size));         image.getGraphics().setColor(c);         image.getGraphics().drawString(text, posLeft, posTop);                  image.getGraphics().dispose();   where image is instance of java.awt.BufferedImage class object, icon is instance of javax.swing.Icon with constructor of class javax.swing.ImageIcon.ImageIcon(Image image). Font is of the class java.awt.Font. Then i'm getting graphics with image.getGraphics(), however null pointer exception occurs while trying to set font part, in line image.getGraphics().setFont(new Font(&quot;Arial&quot;, Font.BOLD, size)); . The error message is only java.lang.NullPointerException: null. I tried changing font but it is still the same. Would very appreciate any help regarding this! (hope i didn't miss some important part) Both image and image.getGraphics() are working, since i checked it in the code and got following: BufferedImage@3c52b5ae: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@35069130 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 659 height = 587 #numDataElements 3 dataOff[0] = 2 ---- sun.java2d.SunGraphics2D[font=java.awt.Font[family=Dialog,name=Dialog,style=plain,size=12],color=java.awt.Color[r=255,g=255,b=255]] ----  where first part above--- is image, and later is image.getGraphics(). Also, I tried using Font f=new Font('Arial',Font.BOLD,size), and there i firstly got null pointer exception and some null value occurring there.
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?
Prove that $\sqrt{n} \le \sum_{k=1}^n \frac{1}{\sqrt{k}} \le 2 \sqrt{n} - 1$ is true for $n \in \mathbb{N}^{\ge 1}$ Gaming with Virtualbox, has it worked for you? Currently I am using Windows 8. I have a virtual box with Ubuntu set up for development. Aside from that I sometimes just want to relax and enjoy a game (Battlefield 3, Skyrim, Saints Row: The Third, etc) after hours of research and development.   I want to have my main machine with linux, and install windows on a virtual box.   What I want to know, from those who have tried or seen it:   How is the performance? I've never been clear on this but, even if I install the correct drivers on the windows box, will it matter? At least on this part, I'm just curious how it offload. Which drivers will matter the most.  Mouse and Keyboard integration, I'll be honest, sometimes the mouse integration in Virtual Box is a bit frustrating, mouse cursor disappears, etc.    I'm not sure if this is the right place to ask. I'm merely trying to come back to linux, yet I'm a PC gamer so I can't throw away Steam. I'm aware of the linux client, but most of those games won't work.   If there's a right place to ask this whether StackExchange sites or any other site let me know.   Cheers and I hope those in the same position find a middle ground. I had to take ownership of the special folder C:\Program Files\WindowsApps to fix . The issue is now resolved, so I'd like to reset the permissions to the way they were before I took ownership of the folder.  I reverted NT SERVICE\TrustedInstaller to the owner and removed my account's permission entries:     But I still have full control of the folder and can browse the folder in Explorer without getting the usual warning that I would have to take ownership:     Is it possible to restore the default permissions of this folder? How to turn cheats on or off How to determine which window manager is running Is there any way (such as a command or environmental variable) to determine what window manager is the one actively running in the current session? Is it possible to install Ubuntu without formatting any partitions? Can I install Ubuntu without formatting any partitions on my hard drive?  I am already running Windows 7 and I want to install Ubuntu as well without formatting any of the partitions I have already created. How check with SOQL if a picklist value is available or not for a specified record type How check if a picklist value is available or not for a specified record type ( through SOQL)? Thanks in advance If $a\neq 1$, find $(a+1)(a^2+1)(a^4+1)\ldots(a^{2^n}+1)$. If $a\neq 1$, find $$(a+1)(a^2+1)(a^4+1)\ldots(a^{2^n}+1)$$   Or i.e.     If $a\neq 1$, find $\prod_{i=0}^n(a^{2^i}+1)$.   It really does seem like $$(a+1)(a^2+1)(a^4+1)\ldots(a^{2^n}+1)=a^{2^n+2^{n-1}+\ldots+2+1}+a^{2^n+2^{n-1}+\ldots+2+1-1}+a^{2^n+2^{n-1}+\ldots+2+1-2}+\ldots+a^2+a+1$$  Or i.e. $$\prod_{i=0}^n(a^{2^i}+1)=\sum_{i=0}^{2^n+2^{n-1}+\ldots+2+1}a^i$$  Is there an interesting proof of this? I'd appreciate any help. How do I batch rename files? I have a few hundred files named hortstu01-01-14 then hortstu01-02-14... Do you get the idea?  Well half of the files are named hortstu_01-03-14 then hortstu_01-04-14.  This messes up sorting the files by name and getting them in the order I'd prefer them to be.  So I'd like to rename the ones without the underscore to hortstu_    Is it possible to do this in a batch operation?  If so how? Why are there so many close votes to review and so few of the others? In the SO Review page , I see the following stats for questions awaiting review:   Close votes:  51.8k (and rising) Suggested edits: 10 (fluctuates, but rarely goes above 20) Everything else: 0 (occasionally see some if you're really lucky)   My question is: Why?  Why are there so many close votes waiting for review? Close votes should expire after four days. And even if there's a good reason for them hanging on longer (ie they're not being viewed), there surely has to be a cut-off eventually after which they can be safely dropped?  And yes, I saw , which is asking basically the same thing. But that was several months ago, and it seems that the queue has hardly moved since then. It seems to me that there's a massive backlog that will never be cleared, and apparently will never expire either. That's not good.  And on the flip side, why are there hardly ever any new user posts or low quality posts to review -- there are always new users posting things, and I recall before this new review system was launched that the list of low quality posts to review was always pretty big. Irreducible cyclotomic polynomial I want to know if there is a way to decide if a cyclotomic polynomial is irreducible over a field $\mathbb{F}_q$? Is an HTTPS query string secure? I am creating a secure web based API that uses HTTPS; however, if I allow the users to configure it (include sending password) using a query string will this also be secure or should I force it to be done via a POST? Describing groups with given presentation? $\langle x,y\ |\ xy=yx,x^5=y^3\rangle$ and $\langle x,y\ |\ xy=yx,x^4=y^2\rangle$. I'm trying to describe the groups with presentations $\langle x,y\ |\ xy=yx,x^5=y^3\rangle$ and $\langle x,y\ |\ xy=yx,x^4=y^2\rangle$. I have some problems getting a good picture of what they look like...   For the first one, $xy=yx$ allows us to say that any element in the group can be written as $x^iy^j$ for some $i,j$. More precisely, using $x^5=y^3$, we can always reduce $j$ to $0,1$ or $2$, whereas $i$ could have any value. So I was thinking about $\mathbb{Z} \times C_3$. But the other way around (reducing $i$ this time) it's also $C_5 \times \mathbb{Z}$. But then I should be able to prove that both descriptions are equivalent, which I can't do...  For the second, I proceed similarly and get to the same kind of problem...  Could you tell me where I'm going wrong?  Thank you very much in advance! Periodically, my MacBook Pro 17" stops recognizing my headphones. No amount of unplugging and replugging seems to help. The sound settings never show headphones as an output device. How can I fix this? The only thing I can find elsewhere on the Internet are people saying, "Reboot!" This works, but is impractical and annoying. I have read so many things already that I'm more confused than before. So decided to ask this by myself.  My paladin just got his Find Steed spell, and after some tweaking and talking, he decided to get a Worg and I was okay with it. This last session was his first time using it and I have few doubts when it comes to combat.  I know that while mounted, he uses the mounts movement and actions. But what about when unmounted? What if the combat began with him walking by his mount's side?   Does the mount share his initiative? Are the actions that the mount do, part of the Paladin's actions? Or are they both separately, having his Action, Movement and Bonus Action and then the mounts Action and movement?   We've stated that it can understand him but not talk back, he just telepathically receives feelings as a feedback to his commands, knowing that the mount understood what he needed. Last session he just said things to the mount like "I tell the mount to protect the ranger and the druid" and in case they got hit, it would attack them, but it didn't really do anything at all, as I didn't know when it would act and I had too many things already to remember about the mount. Idiom for a speech with redundant information Error :: You must put some 'source' URIs in your sources.list I'm trying to install PIL a python module on ubuntu   I first need to install a package called python-imaging using the following command    sudo apt-get build-dep python-imaging   When I try and do this I get the error   E: You must put some 'source' URIs in your sources.list   I saw  question whihc shows how to fix via the GUI but I'm using the command line. Does anyone know how I can fix this error..?    UPDATE: Based on the below answers I've updated my package list but I now get this error. Not sure if it is related, if not I'll start a new question as I can't find reference to the error anywhere.   E: Build-Depends dependency for python-imaging cannot be satisfied because candidate version of package python-all-dev can't satisfy version requirements Finding square root without using sqrt function? How to Select Columns in Editors (Atom,Notepad++, Kate, VIM, Sublime, Textpad,etc) and IDEs (NetBeans, IntelliJ IDEA, Eclipse, Visual Studio, etc) How to differ sessions in browser-tabs?