Search Results

Search found 2 results on 1 pages for 'maskau'.

Page 1/1 | 1 

  • Having trouble binding a ksoap object to an ArrayList in Android

    - by Maskau
    I'm working on an app that calls a web service, then the webservice returns an array list. My problem is I am having trouble getting the data into the ArrayList and then displaying in a ListView. Any ideas what I am doing wrong? I know for a fact the web service returns an ArrayList. Everything seems to be working fine, just no data in the ListView or the ArrayList.....Thanks in advance! EDIT: So I added more code to the catch block of run() and now it's returning "org.ksoap2.serialization.SoapObject".....no more no less....and I am even more confused now... package com.maskau; import java.util.ArrayList; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.PropertyInfo; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport; import android.app.*; import android.os.*; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.view.View; import android.view.View.OnClickListener; public class Home extends Activity implements Runnable{ /** Called when the activity is first created. */ public static final String SOAP_ACTION = "http://bb.mcrcog.com/GetArtist"; public static final String METHOD_NAME = "GetArtist"; public static final String NAMESPACE = "http://bb.mcrcog.com"; public static final String URL = "http://bb.mcrcog.com/karaoke/service.asmx"; String wt; public static ProgressDialog pd; TextView text1; ListView lv; static EditText myEditText; static Button but; private ArrayList<String> Artist_Result = new ArrayList<String>(); @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); myEditText = (EditText)findViewById(R.id.myEditText); text1 = (TextView)findViewById(R.id.text1); lv = (ListView)findViewById(R.id.lv); but = (Button)findViewById(R.id.but); but.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { wt = ("Searching for " + myEditText.getText().toString()); text1.setText(""); pd = ProgressDialog.show(Home.this, "Working...", wt , true, false); Thread thread = new Thread(Home.this); thread.start(); } } ); } public void run() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo pi = new PropertyInfo(); pi.setName("ArtistQuery"); pi.setValue(Home.myEditText.getText().toString()); request.addProperty(pi); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); AndroidHttpTransport at = new AndroidHttpTransport(URL); at.call(SOAP_ACTION, envelope); java.util.Vector<Object> rs = (java.util.Vector<Object>)envelope.getResponse(); if (rs != null) { for (Object cs : rs) { Artist_Result.add(cs.toString()); } } } catch (Exception e) { // Added this line, throws "org.ksoap2.serialization.SoapObject" when run Artist_Result.add(e.getMessage()); } handler.sendEmptyMessage(0); } private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { ArrayAdapter<String> aa; aa = new ArrayAdapter<String>(Home.this, android.R.layout.simple_list_item_1, Artist_Result); lv.setAdapter(aa); try { if (Artist_Result.isEmpty()) { text1.setText("No Results"); } else { text1.setText("Complete"); myEditText.setText("Search Artist"); } } catch(Exception e) { text1.setText(e.getMessage()); } aa.notifyDataSetChanged(); pd.dismiss(); } }; }

    Read the article

  • Parsing a JSON Response from a .Net webservice

    - by Maskau
    Just to get this out in the open I am new to JAVA, KSOAP, and JSON. So I'll try to explain this the best I can. A while ago I created a webservice to be consumed by Blackberry Apps that we're built using the plug in for Visual Studio. Now the project I am working on, I want to consume the same webservice for Android devices. For the most part I have the base code for the Android app done and working. Here's my problem: I can successfully call the webservice and get a response. I know from creating the webservice that it sends a JSON response. My problem is trying to parse through the JSON response. I have found a few examples that I have been suiting to my needs however I am hung up on one thing. In the JSON each element is preceeded by "anyType" which is forcing my code to return no results (Ultimately I am binding the data to an ArrayList) Here's what I get if I "getProperty(0).toString()... anyType{Artist=anyType{TrackName=Champagne Supernova;}; Here is the code I am using to parse the JSON Object.... SoapObject gr = (SoapObject)envelope.getResponse(); String ro = gr.getProperty(0).toString(); //Added just to see structure of response Artist_Result.add(gr.toString()); if (ro.startsWith("{")) { JSONObject JSONObj = new JSONObject(ro); Iterator<String> itr = JSONObj.keys(); while (itr.hasNext()) { String key = (String)itr.next(); String value = JSONObj.getString(key); //bundleResult.putString(key, value); Artist_Result.add(value); } } else if (ro.startsWith("[")) { JSONArr = new JSONArray(ro); for (int i = 0; i < JSONArr.length(); i++) { JSONObj = (JSONObject)JSONArr.get(i); //bundleResult.putString(String.valueOf(i), JSONObj.toString()); Artist_Result.add(JSONObj.toString()); } } WebService Code: [WebMethod] [return: System.Xml.Serialization.XmlArrayItemAttribute(typeof(Artist))] public Artist[] GetArtist(string ArtistQuery) { // All the SQL Stuff Here SqlDataReader sReader; sReader = cmd.ExecuteReader(); List<Artist> Artists = new List<Artist>(); while (sReader.Read()) { Artist result = new Artist(); result.TrackName = sReader.GetString(0); Artists.Add(result); } sReader.Close(); sqlConn.Close(); return Artists.ToArray(); } public class Artist { public string TrackName; } Sample of XML Output from a browser: <?xml version="1.0" encoding="utf-8" ?> - <ArrayOfArtist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://bb.mcrcog.com/"> - <Artist> <TrackName>Champagne Supernova</TrackName> </Artist> - <Artist> <TrackName>Don't Look Back In Anger</TrackName> </Artist> - <Artist> <TrackName>D'you Know What I Mean</TrackName> </Artist> - <Artist> <TrackName>Go Let It Out</TrackName> </Artist> I have a feeling I will need to implement a Class, and Getters/Setters on the Android side. I'm just not sure how to go about doing that. Any help would be greatly appreciated!

    Read the article

1