当我们转换API级别时,我们是否需要在代码中进行更改?

时间:2011-10-19 09:43:17

标签: java android

我已经连接到Web服务并检索了Android设备2.2版API 8中的值。但是当我将版本更改为3.0并将模拟器更改为API 11.相同的代码显示错误。我已经更改了清单文件sdk版本和所有版本。

问题如下:

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
// androidHttpTransport.debug=true;
try{
    androidHttpTransport.call(SOAP_ACTION, envelope);
    // after this line it is going to the catch block
    SoapObject resultString=(SoapObject)envelope.bodyIn;

    // the result string is null when I used debugger and checked
    System.out.println("the result string displayed :" +resultString);
    String result=resultString.getProperty(0).toString();
} catch (Exception e) {
    e.getMessage();
}

Logcat错误如下:

WARN/System.err(886): android.os.NetworkOnMainThreadException
 WARN/System.err(886):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
 WARN/System.err(886):     at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:368)
 WARN/System.err(886):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)
 WARN/System.err(886):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)
 WARN/System.err(886):     at java.net.Socket.connect(Socket.java:901)
 WARN/System.err(886):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
WARN/System.err(886):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
WARN/System.err(886):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
WARN/System.err(886):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
WARN/System.err(886):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
WARN/System.err(886):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
WARN/System.err(886):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:217)
WARN/System.err(886):     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:75)
WARN/System.err(886):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:136)
WARN/System.err(886):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
WARN/System.err(886):     at com.timetracker.app.Index.run(Index.java:214)
WARN/System.err(886):     at com.timetracker.app.Index$1.onClick(Index.java:77)
WARN/System.err(886):     at android.view.View.performClick(View.java:3100)
WARN/System.err(886):     at android.view.View$PerformClick.run(View.java:11644)
WARN/System.err(886):     at android.os.Handler.handleCallback(Handler.java:587)
WARN/System.err(886):     at android.os.Handler.dispatchMessage(Handler.java:92)
WARN/System.err(886):     at android.os.Looper.loop(Looper.java:126)
WARN/System.err(886):     at android.app.ActivityThread.main(ActivityThread.java:3997)
WARN/System.err(886):     at java.lang.reflect.Method.invokeNative(Native Method)
WARN/System.err(886):     at java.lang.reflect.Method.invoke(Method.java:491)
WARN/System.err(886):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
WARN/System.err(886):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
WARN/System.err(886):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

尝试以这种方式写信给你,

public void onCreate() { 
  StrictMode.enableDefaults(); //this line add 
  super.onCreate(); 
  //put your Code
}

告诉我这是否有效......要阅读博客文章,请转到this link here