日期:2014-05-20  浏览次数:20753 次

那位帮忙看下这个程序!谢谢啦
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)
有错误的两行我已经注释出来,希望高手帮忙解决下,谢谢啦!

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

String [] count = temp.clone();
试一下
------解决方案--------------------
count[j] = null;
改成count[j] = “”;就可以了
------解决方案--------------------


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