只有创建视图层次结构的原始线程才能触及其视图

时间:2014-06-18 20:01:13

标签: android exception hierarchy

我知道这个问题之前已被问过很多次,但我真的找不到我具体案例的答案。

我必须承认,我是Android的全新手。

我有一个dot net webservice,它返回一个带有名字的数组列表,我希望这些名字显示在android列表视图中。

显然我的代码工作正常,但我得到的只是创建视图层次结构的原始线程可以触及其视图异常。

我真的不知道替换或改变是什么,我真的不知道,我希望有人可以帮助我。

谢谢!

public class MainActivity extends Activity {

SoapObject response;

/*
 * String list[]; boolean exc = false;
 */

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.otra);

    new addassdist().execute();
}

class addassdist extends AsyncTask<Void, Void, Void> {
    private final ProgressDialog dialog = new ProgressDialog(
            MainActivity.this);

    final String SOAP_ACTION = "http://demo.android.org/directorioLista";
    final String METHOD_NAME = "directorioLista";
    final String NAMESPACE = "http://demo.android.org/";
    final String URL = "http://192.168.10.135/SumadorWS/Service1.asmx";

    @Override
    protected void onPreExecute() {
        this.dialog.setMessage("Loading data");
        this.dialog.show();
    }

    @Override
    protected Void doInBackground(Void... unused) {
        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(Request);
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
                URL);
        ListView lista = (ListView) findViewById(R.id.mainListView);
        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            response = (SoapObject) envelope.getResponse();
            String[] Clientes = getStringArrayResponse(response, null);
            lista.setAdapter(new ArrayAdapter<String>(
                    getApplicationContext(),
                    android.R.layout.simple_list_item_1, Clientes));
        } catch (Exception e) {
            e.printStackTrace();
        }
return null;
    }

    @Override
    protected void onPostExecute(Void result) {

    }

    private String[] getStringArrayResponse(SoapObject node,
            Vector<String> strings) {
        // TODO Auto-generated method stub
        boolean isFirstCall = false;
        if (strings == null) {
            isFirstCall = true;
            strings = new Vector<String>();
        }
        int count = response.getPropertyCount();
        for (int i = 0; i < count; i++) {
            Object obj1 = node.getProperty(i);
            if (obj1 instanceof SoapObject) {
                // don't recurse empty objects
                if (((SoapObject) obj1).getPropertyCount() > 0) {
                    // recurse into another node to process its
                    // nodes/primitives
                    getStringArrayResponse((SoapObject) obj1, strings);
                }
            } else if (obj1 instanceof SoapPrimitive) {
                strings.add(((SoapPrimitive) obj1).toString());
            }
        }
        // only make this for the original caller
        if (isFirstCall) {
            return (String[]) strings.toArray(new String[strings.size()]);
        }
        return null;
    }
}

}

0 个答案:

没有答案