gpt4 book ai didi

java - HttpURLConnection 打开跟踪文件时出错 : no such file or directory

转载 作者:行者123 更新时间:2023-11-29 21:45:56 27 4
gpt4 key购买 nike

我正在尝试连接到一个 url 以获取地理点,以便在我的 android 应用程序的 map View 中绘制一条路线。但是,当我尝试连接到 url 以获取积分时出现此错误。

URL url = new URL("http://maps.google.com/maps?f=d&hl=en&saddr=59.690289,16.60868&daddr=59.6,16.60868&ie=UTF8&0&om=0&output=kml");
Log.d("log","url: " + url);
HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection(); urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
Log.d("log","connected");

我的 list 中有以下内容

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

我正在使用模拟器在 Mac OSX Lion 上的 eclipse 4.2.2 中运行它。

感谢您的帮助!

编辑

抱歉,我遗漏了一些重要信息,这是我 list 中的所有权限

<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

编辑 2

这是完整的错误

04-07 00:24:46.842: E/AndroidRuntime(7280): FATAL EXCEPTION: main
04-07 00:24:46.842: E/AndroidRuntime(7280): java.lang.RuntimeException: Unable to start activity ComponentInfo{markustenghamn.sfsfum/markustenghamn.sfsfum.MapHandlerActivity}: android.os.NetworkOnMainThreadException
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.os.Handler.dispatchMessage(Handler.java:99)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.os.Looper.loop(Looper.java:137)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-07 00:24:46.842: E/AndroidRuntime(7280): at java.lang.reflect.Method.invokeNative(Native Method)
04-07 00:24:46.842: E/AndroidRuntime(7280): at java.lang.reflect.Method.invoke(Method.java:511)
04-07 00:24:46.842: E/AndroidRuntime(7280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-07 00:24:46.842: E/AndroidRuntime(7280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-07 00:24:46.842: E/AndroidRuntime(7280): at dalvik.system.NativeStart.main(Native Method)
04-07 00:24:46.842: E/AndroidRuntime(7280): Caused by: android.os.NetworkOnMainThreadException
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
04-07 00:24:46.842: E/AndroidRuntime(7280): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
04-07 00:24:46.842: E/AndroidRuntime(7280): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
04-07 00:24:46.842: E/AndroidRuntime(7280): at java.net.InetAddress.getAllByName(InetAddress.java:214)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
04-07 00:24:46.842: E/AndroidRuntime(7280): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
04-07 00:24:46.842: E/AndroidRuntime(7280): at markustenghamn.sfsfum.MapHandlerActivity.DrawPath(MapHandlerActivity.java:166)
04-07 00:24:46.842: E/AndroidRuntime(7280): at markustenghamn.sfsfum.MapHandlerActivity.callMap(MapHandlerActivity.java:126)
04-07 00:24:46.842: E/AndroidRuntime(7280): at markustenghamn.sfsfum.MapHandlerActivity.onCreate(MapHandlerActivity.java:89)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.app.Activity.performCreate(Activity.java:5104)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-07 00:24:46.842: E/AndroidRuntime(7280): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-07 00:24:46.842: E/AndroidRuntime(7280): ... 11 more
04-07 00:24:49.343: E/Trace(7297): error opening trace file: No such file or directory (2)

最佳答案

当您尝试在主应用程序线程上访问 Internet 时,您会收到此异常。您需要在不同的线程中执行所有网络 Activity 。您可以使用 AsyncTask来完成这个。

这样做是为了让应用程序保持响应,即使存在对网络的阻塞调用也是如此。您可能还想进一步阅读 here .

关于java - HttpURLConnection 打开跟踪文件时出错 : no such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15857352/

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