nullpointerexception

Is it standard behavior for this code to throw a NullPointerException?

I've had a big problem in some library code, which I've pinned down to a single statement: System.out.println((String) null); Ok, the code doesn't actually look like that, but it certainly calls println with a null argument. Doing this causes my whole applicaio to throw an unexpected NullPointerException. In general, should println t...

Null Safe dereferencing in Java like ?. in Groovy using Maybe monad

I'm working on a codebase ported from Objective C to Java. There are several usages of method chaining without nullchecks dog.collar().tag().name() I was looking for something similar to safe-dereferencing operator ?. in Groovy instead of having nullchecks dog.collar?.tag?.name This led to Maybe monad to have the notion of Nothing ...

Xalan redirect:write , use either of two element values to create name of new .xml file depending on null values.

So I have the following code: <redirect:write select="concat('..\\folder\\,string(filename),'.xml')"> Where "filename" is a tag in the xml source. My problem occurs when filename is null or blank. And this is the case for several of the xml filename tags. So what I am trying to implement is a checking method. This is what I have done:...

Can't place Marker in GWT Maps with Lat & Lng - Null Pointer Exception in map.addOverlay(Marker)

Hi there, I'm trying to add multiple markers to my GWT-Map. If I do it with the geocoder, it works just fine... But I also get the values from a database, so I can place them via Lat Lng. That's the code: public static void markerSetzen(final double lat, final double lon) { /* Markeroptionen setzen */ MarkerOptions markeroptio...

Best practice with respect to NPE and multiple expressions on single line

I'm wondering if it is an accepted practice or not to avoid multiple calls on the same line with respect to possible NPEs, and if so in what circumstances. For example: anObj.doThatWith(myObj.getThis()); vs Object o = myObj.getThis(); anObj.doThatWith(o); The latter is more verbose, but if there is an NPE, you immediately know what...

Android Custom Dialog NullPointerException

I cannot for the life of me figure out why I'm getting a NullPointerException. When a user clicks on a particular image, a dialog window is supposed to pop-up and display a larger version of said image: private OnClickListener coverListener = new OnClickListener() { public void onClick(View v) { showDialog(DIALOG_COVER); } }; ...

Difference between null==object and object==null

Hi I would like to know diff between the above comparisons? I am getting null pointer exception when I check object.getItems() == null. But if I change it to null == object.getItems(), it workes fine. I did look into this http://stackoverflow.com/questions/2938476/what-is-the-difference-between-null-object-and-objectnull-closed But I d...

Twitter integration with C#.NET applications - NULL Pointer Exception

Trying to integrate Twitter with ASP.NET application (Code in C#). This is the code I have written for the first sign in to Twitter. When I debug the application, I do get the token response and the response redirect happens appropriately. However, if I host it on IIS and access it, I get a Null Pointer Exception. Why is that? //Re...

NullPointerException when showing JFileChooser

I show a JFileChooser with this snippet: public File getDestination() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int option = chooser.showSaveDialog(null); if(option == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile().getAbsolutePath();...

Why do I get a nullpointerexception at line ds.getPort in class L1?

import java.awt.; import java.awt.event.; import javax.swing.; import java.io.; import java.net.; import java.util.; public class Draw extends JFrame { /* * Socket stuff */ static String host; static int port; static int localport; DatagramSocket ds; Socket socket; Draw d; Paper p = new Paper(ds); public Draw(int localport, Stri...

Java interface Problem

Hi, I've got an interface: package com.aex; import javax.jws.WebParam; public interface IFonds { double getKoers(); String getNaam(); void setKoers(@WebParam(name="koers") double koers); } And the class: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com...

android newbie question null pointer on ArrayAdapter.setAdapter

Hi All, I have been slowing learning and building my first android app. I'm VERY new to java but have already done a couple of projects in C#, VB.NET (back in the day), Objective-C (have 6 apps in the store) and Fortran (waaaaaaaaaaaaaaaaaaaay back in the day ;) So I just received from overseas a htc legend (I'm not in the US), which...

Why does int num = Integer.getInteger("123") throw NullPointerException?

hi, the following code throws NPE for me: int num = Integer.getInteger("123"); is my compiler invoking getInteger on null since it's static? that doesn't make any sense! can someone explain what's happening? thanks. ...

Why does String.valueOf(null) throw a NullPointerException?

Hi, according to the documentation, the method String.valueOf(Object obj) returns: if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned. But how come when I try do this: System.out.println("String.valueOf(null) = " + String.valueOf(null)); it throws NPE instead? (try it your...

JSONParser getResourceAsStream

Hi! I am working in a project and I need a resource in it. I am trying to get it using this code: InputStream is = JSONParser.class.getResourceAsStream("a.json"); String jsonTxt = IOUtils.toString( is ); The file a.json is located in the main file of the project. The exact problem is: Exception in thread "main" jav...

Autowire throws a NullPointerException.

Hi, I am new to Spring. I have following class where i am using autowire annotation package com.almas; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.test....

Java List.contains() question

According to the documentation, List.contains can throw NullPointerException in this scenario: "if the specified element is null and this list does not support null elements (optional)." I was just trying to think of a List implementation that doesn't allow nulls though, and I'm not aware of any. For example, I can have Array...

Android - How To Override the "Back" button so it doesn't Finish() my Activity?

I currently have an Activity that when it gets displayed a Notification will also get displayed in the Notification bar. This is so that when the User presses home and the Activity gets pushed to the background they can get back to the Activity via the Notification. The problem arises when a User presses the back button, my Activity ge...

android NullPointerException when calling sendBroadcast(intent)

I am trying to display the options menu when a list item is checked in my app. I am doing this by broadcasting an intent when the checkbox is clicked via a listener and a helper class that extends Activity. My code for the helper class is such: public class menuHelper extends Activity{ private void showMenu(int checked){ try{ In...

why does this code throw a NullPointerException?

Eventually I got the answer, but it puzzled me for a while. Why does the following code throws NullPointerException when run? import java.util.*; class WhyNullPointerException { public static void main( String [] args ){ // Create a map Map<String,Integer> m = new HashMap<String,Integer>(); // Get the previ...