我有以下代码:
import java.util.HashMap;
import java.util.Map;
public class Pangram1 {
public static void main(String[] args)
{
Character [] ch = new Character[] {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
HashMap<Character,Integer> map1 = new HashMap<Character,Integer>();
String s = "The quick brown fox jumps over the lazy dog";
int count = 0;
int greater = 0;
for (char character: ch)
{
map1.put(character, count);
}
for(Map.Entry<Character,Integer> entry : map1.entrySet() )
{
System.out.println("key is" + "\t" + entry.getKey() + "\t" + "Value is" + entry.getValue());
}
for(int i = 0; i < s.length();i++)
{
Integer count1 = map1.get(s.charAt(i));
Line 28 ---> count1.intValue();
map1.put(s.charAt(i),new Integer (count1));
if(count1 > greater)
{
greater = count1;
}
}
if(map1.values().contains(1) && greater == 1)
System.out.println("Pangram");
else if(map1.values().contains(0))
System.out.println("Not Pangram");
else if(greater > 1)
System.out.println("Multiple Pangram" + "\t" + greater);
}
}
我收到此错误 线程&#34; main&#34;中的例外情况显示java.lang.NullPointerException 在Pangram1.main(Pangram1.java:28)
我已经尝试了各种各样的方式,以至于不会出现自动装箱/拆箱问题,但仍会出现异常情况。
有人可以帮我吗?
谢谢!