我使用.NET Web服务来绑定微调器。一旦我点击微调器,应用程序崩溃并从头开始。这是我的代码:
public void addItemsOnSpinner2() {
try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION,envelope);
Object soap = (SoapObject)envelope.getResponse();
tables = new Table[((SoapObject) soap).getPropertyCount()];
for (int i = 0; i < tables.length; i++) {
SoapObject pii = (SoapObject) ((SoapObject) soap).getProperty(i);
Table t = new Table();
t.Tableid = pii.getProperty(0).toString();
t.Tablename = pii.getProperty(1).toString();
tables[i] = t;
}
}
catch (Exception e) {
e.printStackTrace();
}
spinner1 = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<Table> adapter = new ArrayAdapter<Table>(this, R.layout.spinner_layout, tables);
adapter.setDropDownViewResource(R.layout.spinner_layout);
spinner1.setAdapter(adapter);
}
以下是错误跟踪:
06-29 05:25:15.334: E/StrictMode(1037): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
06-29 05:25:15.334: E/StrictMode(1037): java.lang.Throwable: Explicit termination method 'end' not called
06-29 05:25:15.334: E/StrictMode(1037): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
06-29 05:25:15.334: E/StrictMode(1037): at java.util.zip.Inflater.<init>(Inflater.java:82)
06-29 05:25:15.334: E/StrictMode(1037): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
06-29 05:25:15.334: E/StrictMode(1037): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
06-29 05:25:15.334: E/StrictMode(1037): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:182)
06-29 05:25:15.334: E/StrictMode(1037): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)
06-29 05:25:15.334: E/StrictMode(1037): at com.example.mydemo.Secondactivity.addItemsOnSpinner2(Secondactivity.java:90)
06-29 05:25:15.334: E/StrictMode(1037): at com.example.mydemo.Secondactivity.onCreate(Secondactivity.java:55)
06-29 05:25:15.334: E/StrictMode(1037): at android.app.Activity.performCreate(Activity.java:5104)
06-29 05:25:15.334: E/StrictMode(1037): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-29 05:25:15.334: E/StrictMode(1037): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-29 05:25:15.334: E/StrictMode(1037): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-29 05:25:15.334: E/StrictMode(1037): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-29 05:25:15.334: E/StrictMode(1037): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-29 05:25:15.334: E/StrictMode(1037): at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 05:25:15.334: E/StrictMode(1037): at android.os.Looper.loop(Looper.java:137)
06-29 05:25:15.334: E/StrictMode(1037): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-29 05:25:15.334: E/StrictMode(1037): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 05:25:15.334: E/StrictMode(1037): at java.lang.reflect.Method.invoke(Method.java:511)
06-29 05:25:15.334: E/StrictMode(1037): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-29 05:25:15.334: E/StrictMode(1037): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
答案 0 :(得分:0)
经过大量研究后我发现了解决方案。 webservice调用或代码没有任何问题。一切都很好,但我使用了以下代码
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
setContentView(R.layout.activity_secondactivity);
我所做的只是评论以下一行
.penaltyDeath()