public class HelloWorld {
public static void Display(String [] temp)
{

String [] count = temp;
int [] number = new int[temp.length];
for (int i =0 ; i < temp.length ; i++)
{
number[i]= 1;
for(int j = 0 ; j< count.length ; j++)
{

if(count[j].equals(temp[i]))//********
{
count[j] = null;
number[i]++;
}
}
}

for (int k = 0  ; k < count.length ; k++)
{
if(count[k].length()==8 && count[k].charAt(3)== '-')
{
System.out.print(count[k]+"  ");
System.out.println(number[k]);
}
}
}
public static void main(String[] args) {        String [] bog = {"sdf-4567" , "124-7563" , "123-4567" , "654-1234" , "12341" , "sdf-1234" , "123-4567" ,"654-1234"};
        
        Display(bog);//************************************
}
}
程序编译时没有错误,执行时却提示错误
Exception in thread "main" java.lang.NullPointerException
at HelloWorld.Display(HelloWorld.java:16)
at HelloWorld.main(HelloWorld.java:37)
有错误的两行我已经注释出来,希望高手帮忙解决下,谢谢啦!

解决方案 »

  1.   

    你的数组引用有问题
    String [] count = temp;
    这句会把引用指向同一个地址

    String [] count = temp.clone();
    试一下
      

  2.   

    count[j] = null;
    改成count[j] = “”;就可以了
      

  3.   

    不过你说的没错我的确是引用了一个地址..谢谢
    已经把String [] count = temp;
    改成String [] count = (String [])temp.clone();
    但是还是不行啊,错误没变.哪个高手再来看看啊
      

  4.   

    就如maco21(柔情主义) 所说的
      

  5.   

    count[j] = null;
    改成count[j] = "";就可以了