Oct 16

This post is also available in: German

A NullPointerException will be thrown in case the Compiler does not have a value with whom he can work.

Eine NullPointer Exception wird ausgegeben, wenn der Compiler keinen Wert hat, mit dem er arbeiten kann:

class Angestellter {

public int PersNr;

public static void main(String args[]) {

Angestellter a = null; // a points to null, PersNr is not intialized
System.out.println(a.PersNr); //  NullPointerException


}

}

An additional – quite often appearing – example:

String s = null;
System.out.println(s.length());
// Same logic is applied here; since s is not initialized there is nothing to access for method length

  • Print
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks
  • Add to favorites
  • RSS
  • Blogosphere
  • email
  • PDF
  • Wikio
  • Technorati
  • Digg
  • DZone

Leave a Reply

preload preload preload
http://www.wikio.de Blog Top Liste - by TopBlogs.de Blogverzeichnis - Blog Verzeichnis bloggerei.de Bloggeramt.de Software
Webbhotell Top Blogs