/** * @author lautturi.com * Java example: java string null */ public class Lautturi { public static void main(String[] args) { String str1 = null; String str2; System.out.println(str1); System.out.println(str2); } }
output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The local variable str2 may not have been initialized
solution:
String str2 = null; OR String str2 = "any string";