我如何解决(错误打开跟踪文件:没有这样的文件或目录(2))在Android中 [英] How Can I Solve ( Error Opening Trace File: No Such File Or Directory (2)) In Android
本文介绍了我如何解决(错误打开跟踪文件:没有这样的文件或目录(2))在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行我的应用程序时我在LogCat中遇到异常错误
打开跟踪文件时出错:没有这样的文件或目录(2 )
即时尝试制作程序连接互联网
i将此标签添加到Manifest文件
清单:
< uses-permission android:name = android.permission.INTERNET / >
我的java:
包 net.learn2develop.http1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import android.util.Log;
public class MainActivity extends 活动{
private InputStream OpenHttpConnection( String urlString)< span class =code-keyword> throws IOException
{
Log.d( Location:, Method-first Line);
InputStream in = null;
int response = - 1 ;
URL url =新网址(urlString);
// 网址url =新网址(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException( 不是Http连接);
尝试
{
Log.d( Locataion:, try bloc);
HttpURLConnection httpConn =(HttpURLConnection)conn;
httpConn.setAllowUserInteraction(false);
httpConn.setFollowRedirects(true);
httpConn.setRequestMethod( GET);
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK){
in = httpConn.getInputStream();
}
}
catch (例外情况)
{
Log.d( Networking,ex.getLocalizedMessage());
throw new IOException( 连接)时出错;
}
返回 in;
}
@覆盖
受保护 void onCreate(Bundle savedInstanceState){
super .onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
任何帮助?
解决方案
每次这段代码都说明一点
@覆盖
受保护 void onCreate(Bundle savedInstanceState){
super .onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
来自MainActivity类中的所有代码
it遇见也会给你带来一些问题。
试试吧。
hi guys .
when i run my app i get an unusual Error in LogCat
Error opening trace file: No such file or directory (2)
im trying to make a program to connect Internet
i added this tag to Manifest File
manifest :
<uses-permission android:name="android.permission.INTERNET"/>
my java :
package net.learn2develop.http1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import android.util.Log;
public class MainActivity extends Activity {
private InputStream OpenHttpConnection(String urlString) throws IOException
{
Log.d("Location:","Method-first Line");
InputStream in=null;
int response=-1;
URL url=new URL(urlString);
//URL url=new URL(urlString);
URLConnection conn=url.openConnection();
if(!(conn instanceof HttpURLConnection))
throw new IOException("Not an Http connection");
try
{
Log.d("Locataion:","try bloc");
HttpURLConnection httpConn=(HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response=httpConn.getResponseCode();
if(response==HttpURLConnection.HTTP_OK){
in=httpConn.getInputStream();
}
}
catch(Exception ex)
{
Log.d("Networking",ex.getLocalizedMessage());
throw new IOException("Error connecting");
}
return in;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
any help ?
解决方案
Make a point the every time this code
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }
Comes before all your code in the MainActivity class
it met also cause you some problems.
Try it.
这篇关于我如何解决(错误打开跟踪文件:没有这样的文件或目录(2))在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文