viernes, 2 de noviembre de 2012

Integer.getInteger() give NULL value

I used before the static function of Integer Class "getInteger()" but rigth now always give me a null pointer in several cases of coding...

Some know if this issue is only on Java 7?

bash-4.1# /usr/java/jdk1.7.0_09/bin/java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)




Code:

public class Test  {
    public static void main(String[] args) {
    String str = new String("10");
    Integer l;
    l = Integer.getInteger(str);
    System.out.println(l);
    }
}

Output:

bash-4.1# /usr/java/jdk1.7.0_09/bin/javac Test.java
bash-4.1# /usr/java/jdk1.7.0_09/bin/java Test
null
--

Code:

public class Test  {
    public static void main(String[] args) {
    Integer l;
    l = new Integer(Integer.getInteger(new String("10")));
    System.out.println(l);
    }
}

Output:

Bash-4.1# /usr/java/jdk1.7.0_09/bin/java Test
Exception in thread "main" java.lang.NullPointerException
    at Test.main(Test.java:4)



--

Code:

public class Test  {
    public static void main(String[] args) {
    Integer l;
    l = Integer.getInteger("10");
    System.out.println(l);
    }
}


Output:

bash-4.1# /usr/java/jdk1.7.0_09/bin/javac Test.java    
bash-4.1# /usr/java/jdk1.7.0_09/bin/java Test    
null

--

Code:

public class Test  {
    public static void main(String[] args) {
    Integer l;
    l = Integer.getInteger(new String("10"));
    System.out.println(l);
    }
}


bash-4.1# /usr/java/jdk1.7.0_09/bin/javac Test.java
bash-4.1# /usr/java/jdk1.7.0_09/bin/java Test
null


--
Linux Version
bash-4.1# uname -a
Linux localhost 3.6.4 #2 SMP Thu Nov 1 11:31:12 CST 2012 x86_64 Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz GenuineIntel GNU/Linux



--
--
Saludos

Exito!!
Publicar un comentario

Buscar en el Blog

Populares siempre