Webサービスクラスでは、オンラインからデータベースを取得し、リストに追加します。
public List<List_NewsComment> allCommentList;
public void GetCommentNews( final int gCommentNewsID)
{
Thread networkThread=new Thread(){
@Override
public void run(){
try
{
SoapObject request= new SoapObject(NAMESPACE,get_Comment_METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
HttpTransportSE androidHttpTransportSE= new HttpTransportSE(URL,60000);
request.addProperty("itemid", gCommentNewsID);
envelope.setOutputSoapObject(request);
androidHttpTransportSE.call(get_Comment_SOAP_ACTION, envelope);
SoapObject result=(SoapObject)envelope.bodyIn;
RetrieveFromSoap( result);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
};
networkThread.start();
}
public List<List_NewsComment> RetrieveFromSoap(SoapObject soap)
{
allCommentList= new ArrayList<List_NewsComment>();
Vector<Object> property2 = extracted(soap);
for (int i = 0; i< property2.size();i++){
SoapObject getPropertyD=(SoapObject)property2.get(i);
List_NewsComment addcomment= new List_NewsComment();
addcomment.setcommentDate(getPropertyD.getProperty("date").toString());
addcomment.setUserName( getPropertyD.getProperty("name").toString());
addcomment.setCommentContent(getPropertyD.getProperty("comment").toString());
allCommentList.add(addcomment);
}
webservice.allCommentList.size(); <-- can call here no problem
return allCommentList;
}
private static Vector<Object> extracted(SoapObject soap) {
return (Vector<Object>)soap.getProperty(0);
}
メインアクティビティクラスで、リストのサイズを確認したい:
Database_WebService webservice = new Database_WebService(this);
webservice.GetCommentNews(newsid);
webservice.allCommentList.size(); <-- cannot call here, what is the problem
それは私を返しますnullpointerexception
。
何が問題ですか????