我想在我的Android应用程序中使用.net Web服务.我通过使用asynctask将请求发送到Web服务.但是请求的价值不正确.我在许多androID应用程序中使用了这种结构,但从未遇到这样的错误.问题是什么?
我有权限(互联网).命名空间和方法名称为true.
public class MainActivity extends Activity { private static final String nameSPACE = "http://tempuri.org/"; private static final String URL = "http://service.melihmucuk.com/ShopArWS.asmx"; private String[][] items; private String[][] GetAllitems(){ SoapObject request = new SoapObject(nameSPACE, "GetAllitem");//faulty line SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setoutputSoapObject(request); httpTransportSE androIDhttpTransport = new httpTransportSE(URL); androIDhttpTransport.deBUG = true; try { androIDhttpTransport.call("http://tempuri.org/GetAllitem", envelope); SoapObject response = (SoapObject) envelope.getResponse(); items[0] = new String[response.getPropertyCount()]; //item_ID items[1] = new String[response.getPropertyCount()]; //price items[2] = new String[response.getPropertyCount()]; //Title items[3] = new String[response.getPropertyCount()]; //desc for(int i=0;i<response.getPropertyCount();i++){ Object property = response.getProperty(i); if(property instanceof SoapObject){ SoapObject item = (SoapObject) property; String item_ID = item.getProperty("item_ID").toString(); String price = item.getProperty("price").toString(); String Title = item.getProperty("Title").toString(); String desc = item.getProperty("desc").toString(); items[0][i] = item_ID; items[1][i] = price; items[2][i] = Title; items[3][i] = desc; } } } catch (Exception e) { e.printstacktrace(); } return items; } public class GetAllitemsAS extends AsyncTask<String,String,String[][]>{ @OverrIDe protected voID onPreExecute() { } @OverrIDe protected String[][] doInBackground(String... params) { GetAllitems(); return items; } protected voID onPostExecute(String[][] items){ ASFinish(); }} public voID ASFinish(){ ListVIEw Liste = (ListVIEw)findVIEwByID(R.ID.ListVIEw1); ListArrayAdapter adapter = new ListArrayAdapter(MainActivity.this,items[0],items[1],items[2],items[3]); Liste.setAdapter(adapter); } @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); items = new String[4][0]; new GetAllitemsAS().execute(); } }
我的LogCat
05-22 01:07:10.201: E/WindowManager(22337): Activity com.zontul.shopar.MainActivity has leaked window com.androID.internal.policy.impl.PhoneWindow$DecorVIEw@414ba3a0 that was originally added here05-22 01:07:10.201: E/WindowManager(22337): androID.vIEw.WindowLeaked: Activity com.zontul.shopar.MainActivity has leaked window com.androID.internal.policy.impl.PhoneWindow$DecorVIEw@414ba3a0 that was originally added here05-22 01:07:10.201: E/WindowManager(22337): at androID.vIEw.VIEwRootImpl.<init>(VIEwRootImpl.java:464)05-22 01:07:10.201: E/WindowManager(22337): at androID.vIEw.WindowManagerImpl.addVIEw(WindowManagerImpl.java:419)05-22 01:07:10.201: E/WindowManager(22337): at androID.vIEw.WindowManagerImpl.addVIEw(WindowManagerImpl.java:351)05-22 01:07:10.201: E/WindowManager(22337): at androID.vIEw.WindowManagerImpl$CompatModeWrapper.addVIEw(WindowManagerImpl.java:171)05-22 01:07:10.201: E/WindowManager(22337): at androID.vIEw.Window$LocalWindowManager.addVIEw(Window.java:558)05-22 01:07:10.201: E/WindowManager(22337): at androID.app.Dialog.show(Dialog.java:282)05-22 01:07:10.201: E/WindowManager(22337): at com.zontul.shopar.MainActivity$GetAllitemsAS.onPreExecute(MainActivity.java:78)05-22 01:07:10.201: E/WindowManager(22337): at androID.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)05-22 01:07:10.201: E/WindowManager(22337): at androID.os.AsyncTask.execute(AsyncTask.java:534)05-22 01:07:10.201: E/WindowManager(22337): at com.zontul.shopar.MainActivity.onCreate(MainActivity.java:115)05-22 01:07:10.201: E/WindowManager(22337): at androID.app.Activity.performCreate(Activity.java:5066)05-22 01:07:10.201: E/WindowManager(22337): at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)05-22 01:07:10.201: E/WindowManager(22337): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2311)05-22 01:07:10.201: E/WindowManager(22337): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)05-22 01:07:10.201: E/WindowManager(22337): at androID.app.ActivityThread.access0(ActivityThread.java:151)05-22 01:07:10.201: E/WindowManager(22337): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)05-22 01:07:10.201: E/WindowManager(22337): at androID.os.Handler.dispatchMessage(Handler.java:99)05-22 01:07:10.201: E/WindowManager(22337): at androID.os.Looper.loop(Looper.java:155)05-22 01:07:10.201: E/WindowManager(22337): at androID.app.ActivityThread.main(ActivityThread.java:5520)05-22 01:07:10.201: E/WindowManager(22337): at java.lang.reflect.Method.invokeNative(Native Method)05-22 01:07:10.201: E/WindowManager(22337): at java.lang.reflect.Method.invoke(Method.java:511)05-22 01:07:10.201: E/WindowManager(22337): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)05-22 01:07:10.201: E/WindowManager(22337): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:796)05-22 01:07:10.201: E/WindowManager(22337): at dalvik.system.NativeStart.main(Native Method)
编辑:我编辑了代码,但不使用对话框.请不要写关于对话框的答案.对话框不会出现问题.
解决方法:
您将需要在onPreExecute而不是在类级别初始化ProgressDialog:
private ProgressDialog dialog; //declare here @OverrIDe protected voID onPreExecute() { dialog = new ProgressDialog(MainActivity.this); //<< initialize here dialog.setMessage("Loading..."); dialog.show(); } //.....protected voID onPostExecute(String[][] items){ ASFinish(); if(null !=dialog) if(dialog.isShowing()) dialog.dismiss();}
总结 以上是内存溢出为你收集整理的Android AsyncTask SoapObject请求问题全部内容,希望文章能够帮你解决Android AsyncTask SoapObject请求问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)