JavaNullPointer填充数组的异常

时间:2014-10-02 15:19:30

标签: android arrays android-studio

我正在执行此代码:

 HttpTransportSE transportSE = new HttpTransportSE(URL);
            try{
                //Web service call
                transportSE.call(SOAP_ACTION_BRING_NEEDS, envelope);

                //create SoapPrimitive and obtain response
                resultsRequestSOAP = (SoapObject)envelope.getResponse();

                int intPropertyCount = resultsRequestSOAP.getPropertyCount();
                strNeeds = new String[intPropertyCount];

                for(int i= 0;i< intPropertyCount; i++)
                {
                    //strNeeds[i]= resultsRequestSOAP.getPropertyAsString(i).toString();
                    //Format the information from the web service
                    Object property = resultsRequestSOAP.getProperty(i);
                    if (property instanceof SoapObject) {
                        SoapObject needsList = (SoapObject) property;
                        strNeeds[i] = needsList.getProperty("Descripcion").toString();
                        strCodeNeeds[i] = needsList.getProperty("Codigo").toString();
                    }
                }
            }catch (Exception e){
                exc = true;
                e.printStackTrace();
            }

并在这行代码上制动:

 strCodeNeeds[i] = needsList.getProperty("Codigo").toString();

异常和java.lang.NullPointerException上的错误suppressedExceptions = {java.util.Collections$EmptyList@830033977576} = 0

我把手表放在&#34; needList&#34;迭代&#34; For&#34;它在position 0 = anyType{Codigo=3; CodigoClase=1; Descripcion=Acceso a puerto; }

中包含此结果

并且数组strNeeds[i]正确填充。

知道发生了什么事吗?谢谢你的建议。

1 个答案:

答案 0 :(得分:0)

这会导致教程错误!他们忘了初始化strCodeNeeds,

strCodeNeeds = new String[intPropertyCount];