Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi


I'm fresher to Android.

I need to fill the android listview from dataset using JSON webservices with the help of KSoap2.

I goggled but didn't get proper solution or tutorial to it.

I tried this example but throws the error as

"the application tracking has stoppped unexpectedly please try again-Force CLose"

Here is my code:

Java
SessionManager session;
				private static final String Soap_Action_JSONEXP="http://tempuri.org/Cargonet_tracking";
				private static final String METHOD_NAME_JSONEXP="Cargonet_tracking";
				private static final String NAMESPACEEXP="http://tempuri.org/";
				private static final String URL_jsEXP="http://192.168.1.126/testing/Cargo_Tracking.asmx/Cargonet?wsdl";
				private String TAG="Cargo";
				//String contentType = "application/json";
				ListView lv;
				private static String responseJSON;
				ProgressBar pg;
				Gson gson=new Gson();
				public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
				    session=new SessionManager(getActivity());
				    session.checkLogin();
				    View view=inflater.inflate(R.layout.activity_main,container,false);
				    return view;    
				}
				@Override
				public void onActivityCreated(Bundle savedInstanceState){
				    super.onActivityCreated(savedInstanceState);
				    lv=(ListView)getActivity().findViewById(R.id.listView1);
				    Thread cmdthredlista=new Thread(){
				    	
				    	
				    			
				        @Override
				    public void run(){
				            SoapObject cmdrequest=new SoapObject(NAMESPACEEXP,METHOD_NAME_JSONEXP);
				            System.out.println("requsest "+cmdrequest);
				            SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
				            envelope.dotNet=true;
				            envelope.setOutputSoapObject(cmdrequest);
				            HttpTransportSE ahttptransport=new HttpTransportSE(URL_jsEXP);
				            try {
				                ahttptransport.call(Soap_Action_JSONEXP,envelope);
				                //final SoapPrimitive response=(SoapPrimitive)envelope.getResponse();
				                SoapPrimitive response=(SoapPrimitive)envelope.getResponse();
				                responseJSON=response.toString();
				                getActivity().runOnUiThread(new Runnable() {
				                    @Override
				                    public void run() {
				                        try {
				                            String[] placelist;              
				                            placelist=gson.fromJson(responseJSON,String[].class);
				                            ArrayAdapter<String>cmdlistaadapteri;
				                            cmdlistaadapteri=new ArrayAdapter<String>(getActivity(),android.R.layout.activity_list_item,placelist);
				                            lv.setAdapter(cmdlistaadapteri);
				                        }
				                        catch (Exception e){
				                            e.printStackTrace();
				                            System.out.println("error ");
				                        }
				                    }
				                });
				            }
				            catch (Exception e){
				                e.printStackTrace();
				                System.out.println("error ");
				            }
				        }
				    };
				    cmdthredlista.start();
				}


	public String getTAG() {
		return TAG;
	}
	public void setTAG(String tAG) {
		TAG = tAG;
	}




Can any one please help me.
Posted
Comments
Krunal Rohit 2-Apr-14 11:19am    
Have you seen the Logcat for what the actual error is ?

-KR

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900