我得到一个NullPointerException
并且无法弄清楚为什么。我在这里阅读了很多问题,似乎无法很好地剖析任何内容以获得我需要的答案。我正在使用 aHashMap
并且我正在尝试从不同的模块中引用它。
这是代码:
import java.util.*;
@SuppressWarnings("unused")
public class Decoder
{
public static void main(String[] args)
{
decrypt();
keywork(null);
}
static void decrypt()
{
String codedline = "ilyh wkrxvdqg, wzr kxqguhg dqg qlqhwb-wkuhh".toLowerCase();
char[] cwarr = codedline.toCharArray();
String dcline = "";
for(char x : cwarr)
{
if(Character.isLetter(x))
{
int c = (int)x;
c = c - 3;
if(c > 90 && c < 97)
{
c += 26;
}
x = (char)c;
dcline += x;
} else
{
dcline += x;
}
}
System.out.println(dcline);
}
static void keywork(String dcline)
{
int x;
for(int i = 1, sw = 0; i == dcline.length(); i++)
{
String strchk = dcline.substring(sw, i);
Object n = hm.get(strchk);
};
}
static final HashMap<String, Integer> hm = new HashMap <String, Integer>()
{
/**
*
*/
private static final long serialVersionUID = 2688387173090905196L;
{
hm.put("ONE", 1);
hm.put("TWO", 2);
hm.put("THREE", 3);
hm.put("FOUR", 4);
hm.put("FIVE", 5);
hm.put("SIX", 6);
hm.put("SEVEN", 7);
hm.put("EIGHT", 8);
hm.put("NINE", 9);
hm.put("TEN", 10);
hm.put("ELEVEN", 11);
hm.put("TWELVE", 12);
hm.put("THIRTEEN", 13);
hm.put("FOURTEEN", 14);
hm.put("FIFTEEN", 15);
hm.put("SIXTEEN", 16);
hm.put("SEVENTEEN", 17);
hm.put("EIGHTEEN", 18);
hm.put("NINETEEN", 19);
hm.put("TWENTY", 20);
hm.put("THIRTY", 30);
hm.put("FOURTY", 40);
hm.put("FIFTY", 50);
hm.put("SIXTY", 60);
hm.put("SEVENTY", 70);
hm.put("EIGHTY", 80);
hm.put("NINETY", 90);
hm.put("HUNDRED", 100);
hm.put("THOUSAND", 1000);
}
};
}
这就是我得到的:
java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at Decoder$1.<init>(Decoder.java:56)
at Decoder.<clinit>(Decoder.java:49)
Exception in thread "main"