Eclipse 如何在android项目中运行单个文件类进行测试?
我是android新手。我已经建立了一个项目 我有一个类检查url是否存在,如下所示:Eclipse 如何在android项目中运行单个文件类进行测试?,eclipse,Eclipse,我是android新手。我已经建立了一个项目 我有一个类检查url是否存在,如下所示: public class connect { Boolean checkServer() throws IOException { Boolean check = false; HttpURLConnection connection = null; try { URL url = new URL("www.google.com"); connectio
public class connect {
Boolean checkServer() throws IOException
{
Boolean check = false;
HttpURLConnection connection = null;
try {
URL url = new URL("www.google.com");
connection = (HttpURLConnection) url.openConnection();
connection.connect();
connection.getInputStream();
// do something with the input stream here
check = true;
} catch (MalformedURLException e1) {
e1.printStackTrace();
check = false;
}
finally {
if(null != connection) { connection.disconnect(); }
}
return check;
}
}
我想在eclipse中将其作为单个文件运行
我该怎么做
无论如何谢谢您可以编写一个Junit类,或者以一种简单的方式,使用public static void main()方法或在同一个类中使用main()方法编写一个新类。您应该创建该类的对象并启动main()方法 publicstaticvoidmain(String[]args)抛出IOException{Boolean check=checkServer();if(check){System.out.println(“thánh công”);}},但当我运行时,它显示消息“aunching遇到了无法连接到vm的问题”,我如何解决这个问题?
public class ConnectDemo {
/**
* @param args
*/
public static void main(String[] args) {
Connect c = new Connect();
if(c.checkServer())
System.out.println("Check Server Successful");
else
System.out.println("Check Server not Successful");
}
}