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...
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 are null pointer exceptions and what causes them in general?
...
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...
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...
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...
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 ...
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...
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 ...
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...
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 ...
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...
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...
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...
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...
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...
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...
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.
...
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] -------...
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;
...