nullpointerexception

Eclipse Upgrade Not Working

你离开我真会死。 提交于 2019-12-17 09:53:27
问题 My Eclipse out of the blue stopped building my Android so I removed the old version and have installed Indigo. When I try to import an Android project in I get this error: Errors occurred during the build. Errors running builder 'Android Resource Manager' on project 'ACCUWX_HoneyComb'. java.lang.NullPointerException Errors running builder 'Android Pre Compiler' on project 'ACCUWX_HoneyComb'. java.lang.NullPointerException Errors running builder 'Java Builder' on project 'ACCUWX_HoneyComb'.

Spring Boot - Environment @Autowired throws NullPointerException

耗尽温柔 提交于 2019-12-17 09:41:35
问题 I have a project setup using Spring Boot 0.5.0.M5 . In one of the configuration files I am trying to @Autowire Environment but that fails with a NullPointerException . Here's what I have so far: Application.java @EnableAutoConfiguration @Configuration @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } JpaConfig.java where I am trying to @Autowire Environment @Configuration @EnableTransactionManagement

Spring Boot - Environment @Autowired throws NullPointerException

人盡茶涼 提交于 2019-12-17 09:41:20
问题 I have a project setup using Spring Boot 0.5.0.M5 . In one of the configuration files I am trying to @Autowire Environment but that fails with a NullPointerException . Here's what I have so far: Application.java @EnableAutoConfiguration @Configuration @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } JpaConfig.java where I am trying to @Autowire Environment @Configuration @EnableTransactionManagement

Java array, NullPointerException?

孤街醉人 提交于 2019-12-17 06:56:19
问题 I declared two cards: Card card1 = new Card('3', Card.Suit.clubs); Card card2 = new Card('T', Card.Suit.diamonds); This works: Hand hand1 = new Hand(); hand1.takeCard(card1); But why does this not work? It gives me a NullPointerException on second line: Hand[] hand = new Hand[2]; hand[0].takeCard(card2); 回答1: You are declaring an array of 2 hands. This is just setting up the array. You then need to instantiate the hand objects inside the array. Say hand[0] = new Hand(); hand[1] = new Hand();

Why use Optional.of over Optional.ofNullable?

假如想象 提交于 2019-12-17 05:33:07
问题 When using the Java 8 Optional class, there are two ways in which a value can be wrapped in an optional. String foobar = <value or null>; Optional.of(foobar); // May throw NullPointerException Optional.ofNullable(foobar); // Safe from NullPointerException I understand Optional.ofNullable is the only safe way of using Optional , but why does Optional.of exist at all? Why not just use Optional.ofNullable and be on the safe side at all times? 回答1: Your question is based on assumption that the

Java conditional operator ?: result type

我与影子孤独终老i 提交于 2019-12-17 05:01:22
问题 I'm a bit puzzled about the conditional operator. Consider the following two lines: Float f1 = false? 1.0f: null; Float f2 = false? 1.0f: false? 1.0f: null; Why does f1 become null and the second statement throws a NullPointerException? Langspec-3.0 para 15.25 sais: Otherwise, the second and third operands are of types S1 and S2 respectively. Let T1 be the type that results from applying boxing conversion to S1, and let T2 be the type that results from applying boxing conversion to S2. The

java.lang.NullPointerException is thrown using a method-reference but not a lambda expression

随声附和 提交于 2019-12-17 05:01:17
问题 I've noticed something weird about unhandled exceptions using Java 8 method reference. This is my code, using the lambda expression () -> s.toLowerCase() : public class Test { public static void main(String[] args) { testNPE(null); } private static void testNPE(String s) { Thread t = new Thread(() -> s.toLowerCase()); // Thread t = new Thread(s::toLowerCase); t.setUncaughtExceptionHandler((t1, e) -> System.out.println("Exception!")); t.start(); } } It prints "Exception", so it works fine. But

Why does null reference print as “null”

喜你入骨 提交于 2019-12-17 04:33:28
问题 In println, here o.toString() throws NPE but o1, does not. Why? public class RefTest { public static void main(String[] args) { Object o = null; Object o1 = null; System.out.println(o.toString()); //throws NPE System.out.print(o1); // does not throw NPE } } 回答1: It might help showing you the bytecode. Take a look at the following javap output of your class: > javap -classpath target\test-classes -c RefTest Compiled from "RefTest.java" public class RefTest extends java.lang.Object{ public

Why does null reference print as “null”

折月煮酒 提交于 2019-12-17 04:33:05
问题 In println, here o.toString() throws NPE but o1, does not. Why? public class RefTest { public static void main(String[] args) { Object o = null; Object o1 = null; System.out.println(o.toString()); //throws NPE System.out.print(o1); // does not throw NPE } } 回答1: It might help showing you the bytecode. Take a look at the following javap output of your class: > javap -classpath target\test-classes -c RefTest Compiled from "RefTest.java" public class RefTest extends java.lang.Object{ public

Best explanation for languages without null

喜欢而已 提交于 2019-12-17 04:09:40
问题 Every so often when programmers are complaining about null errors/exceptions someone asks what we do without null. I have some basic idea of the coolness of option types, but I don't have the knowledge or languages skill to best express it. What is a great explanation of the following written in a way approachable to the average programmer that we could point that person towards? The undesirability of having references/pointers be nullable by default How option types work including strategies