0

How do I store data in an array which is in an object? The object contains data retrieved from a webservice.

Here is my code:

package projects.ksoap2sample;

import android.app.Activity;
import android.os.Bundle;
import org.ksoap2.SoapEnvelope;  
import org.ksoap2.serialization.SoapObject;  
import org.ksoap2.serialization.SoapSerializationEnvelope;  
import org.ksoap2.transport.HttpTransportSE;  
import android.widget.Button;
import android.view.View.OnClickListener;
//import com.example.android.R;

import android.app.*;  
import android.os.*;  
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;    
public class ksoap2sample extends Activity {      /** Called when the activity is first created. */      
    private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";      
    private static final String METHOD_NAME = "HelloWorld";      
    private static final String NAMESPACE = "http://tempuri.org/";      
    private static final String URL = "http://173.161.245.235/test/Service.asmx";      
    TextView tv; 
    String[] results;
    @Override      
    public void onCreate(Bundle savedInstanceState) {          
    super.onCreate(savedInstanceState);          
    setContentView(R.layout.main);

    tv=(TextView)findViewById(R.id.TextView01);
    call();
    }
    /* try 
    {                
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);                
    //request.addProperty("prop1", "myprop");                
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);              
    envelope.dotNet=true;              
    envelope.setOutputSoapObject(request);                
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);                
    androidHttpTransport.call(SOAP_ACTION, envelope);                
    Object result = (Object)envelope.getResponse();                 
    String[] results = (String[])  result;              
    tv.setText( ""+results[0]);           
    } 
    catch (Exception e) 
    {              
    tv.setText(e.getMessage());              
    }      
    }  */


    public void call()
    {
            try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

           // request.addProperty("passonString", "Rajapandian");

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);

            Object result = (Object)envelope.getResponse();
            String str1=result.toString();

            System.out.println("length="+result.toString().length());


            for(int i=0;i<str1.length();i++)
            {

                int j=str1.indexOf(";");
                String str=str1.substring(0, j);
                results[i]=str;
                System.out.println("Result="+results[i]);

                /*results[i]=result.toString();
                if(results[i]==";")
                {
                    results[i].i
                }*/
                //String[] results = (String[])  result;
                //result.toString().endsWith(";");

                //results[i]=result.toString().endsWith(";");


           // String[] results = (String[])  result;
            tv.setText( ""+results[i]); 
            }

            tv.setText(result.toString());
            /*SoapObject result=(SoapObject)envelope.getResponse();

          //to get the data
          String resultData=result.getAttribute(1).toString();
          // 0 is the first object of data 
          System.out.println("Result"+resultData);
          tv.setText(resultData.toString());*/
        } catch (Exception e) {
            tv.setText(e.getMessage());
            }
    }


}

This is my code but the results[i] stores a null value. What do I do?

1
  • Are you looking for Object foo; and then foo.array[i] = "Data";Do you have a minimal example? Commented Mar 12, 2011 at 13:28

2 Answers 2

1

Given that "data retrieved from webservice" is held in an instance of a class named Foo, the array would be a Foo[] local variable or data member, as you can see in some Java documentation.

Sign up to request clarification or add additional context in comments.

Comments

0

Object.ArrayName.add() assuming ur Array is a ArrayList or Object.ArrayName[Index] general Array

You must make sure the Array Element is public inside the class. or accessed via Getter Methods

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.