nullpointerexception

IllegalArgumentException or NullPointerException for a null parameter?

I have a simple setter method for a Java property and null is not appropriate for this particular property. I have always been torn, in this situation: should I throw an IllegalArgumentException, or a NullPointerException? From the javadocs, both seem appropriate. Is there some kind of understood standard? Or is this just one of thos...

No stack trace generated on client site for NullPointerException?

I've been learning Java for about a month now, and not very familiar with a client/server situation like this one. Basically I ran into a situation where our client java software (GUI) displayed a nullpointerexception popup but no stack trace on the client side. Someone had to go check the server side for the stack trace. My question i...

What is a Null Pointer Exception?

What are null pointer exceptions and what causes them in general? ...

Applet - 'java.lang.NullPointerException: null pData' when browser closed

I have one user who gets an error message when he closes his browser. This only happens when he has visited a page which contains my applet. It seems to have been registered as a bug at Sun but that was many years ago. He is using Java 1.6 and IE7. Has anyone seen this before and know a solution or work-around? java.lang.NullPointerExc...

How to avoid "!= null" statements in Java?

I work with java all day long. The most used idiom (code snippet) I'm programing in java, is to test if an object != null before I use it, to avoid a NullPointerException of course. But the code looks very ugly and becomes unreadable. Is there a good alternative to avoid this code snippet? Update: Pan, I was not clear with my question...

Problems using Graphics with Panels in the Java Swing Library

Hey everyone, I am trying to run the following program, but am getting a NullPointerException. I am new to the Java swing library so I could be doing something very dumb. Either way here are my two classes I am just playing around for now and all i want to do is draw a damn circle (ill want to draw a gallow, with a hangman on it in the e...

Multi-threading: Objects being set to null while using them.

I have a small app that has a Render thread. All this thread does is draw my objects at their current location. I have some code like: public void render() { // ... rendering various objects if (mouseBall != null) mouseBall.draw() } Then I also have some mouse handler that creates and sets mouseBall to a new ball when the ...

Java NullPointerException when traversing a non-null recordset

Hello again - I am running a query on Sybase ASE that produces a ResultSet that I then traverse and write the contents out to a file. Sometimes, this will throw a NullPointerException, stating that the ResultSet is null. However, it will do this after printing out one or two records. Other times, with the same exact input, I will receiv...

How to trace a NullPointerException in a chain of getters

If I get a NullPointerException in a call like this: someObject.getSomething().getSomethingElse(). getAnotherThing().getYetAnotherObject().getValue(); I get a rather useless exception text like: Exception in thread "main" java.lang.NullPointerException at package.SomeClass.someMethod(SomeClass.java:12) I find it rather hard to ...

How to check if array element is null to avoid NullPointerException in Java

I have a partially nfilled array of objects, and when I iterate through them I tried to check to see whether the selected object is null before I do other stuff with it. However, even the act of checking if it is null seem to through a NullPointerException. array.length will include all null elements as well. How do you go about checking...

Null pointer exception JLabel

Why do I get a null pointer exception when I try and run this on a label: JLabel player1CurrentScore = new JLabel("" + matchPlay.returnPL1GamesWon(), JLabel.CENTER); Is it because I cannot have two strings concatenated like this? Ideally, I am trying to set the label as the score of the player ...

NullPointerException while using put method of HashMap

The following code is giving me a NullPointerException. The problem is on the following line: ... dataMap.put(nextLine[0], nextLine[6]); What is strange is that I have run this code without the above line and the call to nextLine[0] and nextLine[6] work exactly as expected - that is they give me back elements of a csv file. I declar...

weird null pointer exception from VB code

Hello everyone, I am using Windows Vista x64 + VSTS 2008. I am debugging the sample program from the following URL (associated sample code for this article), http://www.codeproject.com/KB/audio-video/CaptureScreenAsVideo.aspx?display=PrintAll&fid=129831&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=101&am...

NullPointerException using ImageIO.read

I'm getting an NPE while trying to read in an image file, and I can't for the life of me figure out why. Here is my line: BufferedImage source = ImageIO.read(new File(imgPath)); imgPath is basically guaranteed to be valid and right before it gets here it copies the file from the server. When it hits that line, I get this stack trace...

Why does my servlet stacktrace show "Unknown Source" for my classes?

I'm currently using Apache Tomcat 5.5.16 to serve a Lucene-based search API. Lately I've been having some NullPointerExceptions inside my servlet class. The class is called com.my_company.search.servlet.SearchServlet. With certain types of input I can routinely create a NullPointerException, but I'm having trouble figuring out where e...

Gracefully avoiding NullPointerException in Java

Consider this line: if (object.getAttribute("someAttr").equals("true")) { // .... Obviously this line is a potential bug, the attribute might be null and we will get a NullPointerException. So we need to refactor it to one of two choices: First option: if ("true".equals(object.getAttribute("someAttr"))) { // .... Second option: S...

How to avoid NullPointerException when using custom Views or SurfaceViews

Hi, I created a custom SurfaceView called CaptureView and tried to add it into main.xml file: <dev.recorder.client.CaptureView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/capturePreview"/> The application seems to work fine but if I switch from main.xml tab to Layout in Eclipse the text N...

Experience with JDK 1.6.x G1 ("Garbage First")

I'd like to know what are the experiences with G1 garbage collector in newest JDK? I see NullPointerException thrown in my program, although code didn't change and behave correctly in earlier JDKs. ...

Maven assembly plugin fails with NullPointerException?

I get a NullPointerException and I don't like it. It is a larger build with several submodules (which differ in their maven config only slightly), for most of the modules it does work, but for some not. Any ideas what the problem might be? [INFO] [assembly:assembly] [INFO] Reading assembly descriptor: src/assemble/all.xml [INFO] -------...

NullPointerException stack trace not available without debug agent

Hi all, I have recently found a bug that causes a NullPointerException. The exception is caught and logged using a standard slf4j statement. Abridged code below: for(Action action : actions.getActions()) { try { context = action.execute(context); } catch (Exception e) { logger.error("...", e); break; ...