简体   繁体   English

HttpURLConnection打开跟踪文件时出错:没有这样的文件或目录

[英]HttpURLConnection Error opening trace file: no such file or directory

I am trying to connect to an url to get geopoints to draw a route in a mapview for my android app. 我正在尝试连接到网址以获取地理位置,以便在android应用的mapview中绘制路线。 However I get this error when I try to connect to the url to get the points. 但是,当我尝试连接到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");

I have the following in my manifest 我的清单中有以下内容

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

I am running this in eclipse 4.2.2 on Mac OSX Lion using the emulator. 我正在使用模拟器在Mac OSX Lion的eclipse 4.2.2中运行它。

Thanks for your help! 谢谢你的帮助!

EDIT 编辑

Sorry, I left out some important info, here are all my permissions in my manifest 抱歉,我遗漏了一些重要信息,这是我清单中的所有权限

<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" />

EDIT 2 编辑2

here is the full error 这是完整的错误

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)

As you are trying to access Internet on the main Application thread, you are getting this exception. 当您尝试在主应用程序线程上访问Internet时,会遇到此异常。 You need to do all network activity in a different thread. 您需要在不同的线程中进行所有网络活动。 You can use AsyncTask to accomplish this. 您可以使用AsyncTask完成此操作。

This is done so the the application will stay responsive even if there are blocking calls to the network. 这样做是为了即使阻塞了对网络的呼叫,应用程序也将保持响应。 You may also want to read further here . 您可能还想在这里进一步阅读。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打开跟踪文件时出错:没有这样的文件或目录(2),解决方案? - error opening trace file: No such file or directory (2), Solution? 打开跟踪文件时出错。 没有这样的文件或目录[2] - Error opening trace file. No such file or directory [2] Android - 错误打开跟踪文件:没有这样的文件或目录 - Android - error opening trace file: No such file or directory E / Trace:错误打开跟踪文件:没有这样的文件或目录(2) - E/Trace﹕ error opening trace file: No such file or directory (2) Android E / Trace(627):打开跟踪文件时出错:没有这样的文件或目录(2) - Android E/Trace(627): error opening trace file: No such file or directory (2) Android运行时错误:打开跟踪文件时出错:没有这样的文件或目录(2) - Android runtime error: error opening trace file: No such file or directory (2) LogCat错误打开跟踪文件时出错:没有这样的文件或目录 - LogCat error Error opening trace file: no such file or directory 是什么原因导致打开跟踪文件错误:没有这样的文件或目录? - What cause the error opening trace file: No such file or directory? Android上的JDom:打开跟踪文件时出错:没有这样的文件或目录 - JDom on Android: error opening trace file: No such file or directory 打开跟踪文件时出错:没有这样的文件或目录(2)Google日历 - error opening trace file: No such file or directory (2) Google Calendar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM