gpt4 book ai didi

java - 当我们改变 API 级别时,代码中是否需要更改任何内容?

转载 作者:行者123 更新时间:2023-12-01 15:42:28 26 4
gpt4 key购买 nike

我已连接到 Web 服务并检索了 Android 设备版本 2.2、API 8 中的值。但是当我将版本更改为 3.0 并将模拟器更改为 API 11 时,相同的代码显示错误。我已经更改了 list 文件 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)

最佳答案

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

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

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

关于java - 当我们改变 API 级别时,代码中是否需要更改任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7819348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com