我已经开始通过YouTube视频和在线教程学习selenium ..
我现在已经掌握了Java中的创建类,接口,对象,继承,数组和循环的知识.
就Selenium而言,我可以使用Java语言直接在Selenium中自动化,方法是使用Firebug/Firepath工具识别每个元素.
但我不断听说TestNG和JUnit框架......
我创建了一个ant构建文件来将我的java src编译成.jar文件.它使用外部jar文件.
我的文件目录:
+src
----android
------------Address.java
------------HelloServer.java
------------HelloServerResource.java
+lib
------------org.codehaus.jackson.core.jar
------------org.codehaus.jackson.mapper.jar
------------org.json.jar
------------org.restlet.ext.jackson.jar
------------org.restlet.jar
build.xml
Run Code Online (Sandbox Code Playgroud)
外部库位于lib文件夹中.主类在HelloServer.java中
这是我的ant构建文件:
<project name="helloworld">
<property name="src-dir" location="src"/>
<property name="build-dir" location="build"/>
<property name="classes-dir" value="${build-dir}/classes"/>
<property name="dist-dir" location="dist"/>
<property name="lib-dir" value="lib"/>
<property name="jar-dir" value="${build-dir}/jar"/>
<property name="main-class" value="android.HelloServer"/>
<path id="classpath">
<fileset dir="${lib-dir}" includes="**/*.jar"/>
</path>
<target name="clean" description="compile the source">
<delete dir="${build-dir}" />
<delete dir="${dist-dir}" />
</target>
<target name="cleanall" depends="clean"/>
<target name="init">
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build-dir}"/>
<mkdir dir="${classes-dir}"/>
<mkdir dir="${jar-dir}"/>
<!--<mkdir …Run Code Online (Sandbox Code Playgroud) 我在这里遇到了一些代码,而我正在尝试将字符串转换为ASCII值,从中减去30然后转换回字符串.
E.g. Enter - hello
Convert to - 104 101 108 108 111
Subtract - 74 71 78 78 81
display - JGNNQ
Run Code Online (Sandbox Code Playgroud)
码:
import javax.swing.*;
public class practice {
public static void main (String[] args) {
String enc = "";
String encmsg = "";
String msg = JOptionPane.showInputDialog("Enter your message");
int len = msg.length();
for (int i = 0; i< len ; i++) {
char cur = msg.charAt(i);
int val = (int) cur;
val = val -32;
enc = …Run Code Online (Sandbox Code Playgroud) 我想注入默认的Java记录器.然而,Eclipse强调它并指出"没有bean有资格注入注射点[JSR-299§5.2.1]"
如果我仍然部署,则抛出以下异常.为什么它无法注入Java Logger?对于EntityManager也是如此,但对于我自己的UserRepository Bean则不行.
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@Default] at injection point [[field]
Run Code Online (Sandbox Code Playgroud)
码:
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import com.terry.webapp.data.UserRepository;
import com.terry.webapp.model.usermgmt.User;
// The @Stateless annotation eliminates the need for manual transaction demarcation
@Stateless
public class LoginService {
@Inject
private Logger log;
@Inject
private EntityManager em;
@Inject
private UserRepository repository;
public User login(User user) {
log.info("login " + user.getUsername());
User rUser = repository.findByCredentials(user.getUsername(), user.getPassword());
return rUser;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在解析这样的日期: "Sat, 30 Jan 2016 00:03:00 +0300"
但在某些日期它给我这个例外:
Caused by: java.time.DateTimeException: Conflict found: Field DayOfWeek 6 differs from DayOfWeek 2 derived from 2016-01-30
Run Code Online (Sandbox Code Playgroud)
或这个:
java.time.format.DateTimeParseException: Text 'Tue, 30 Jan 2016 00:06:00 +0300' could not be parsed: Conflict found: Field DayOfWeek 6 differs from DayOfWeek 2 derived from 2016-01-30
Run Code Online (Sandbox Code Playgroud)
这是我的一些代码:
DateTimeFormatter newformatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
OffsetDateTime odt = OffsetDateTime.parse( date , newformatter );
Instant instant = odt.toInstant();
java.sql.Timestamp ts = java.sql.Timestamp.from( instant );
Run Code Online (Sandbox Code Playgroud)
输入例如抛出异常:
Input:"Tue, …Run Code Online (Sandbox Code Playgroud) 我从AsyncTask中的数据库中获取数据,如果它为null,我想要Toast一个警告文本.我在AsyncTask中尝试但是我知道它不是在工作线程中调用的.这是我的doInBackground方法:
protected String doInBackground(Boolean... params) {
String result = null;
StringBuilder sb = new StringBuilder();
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet( "http://191.162.2.235/getProducts.php?login=1&user_name="+UserName+"&user_pass="+Password);
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() != 200) {
Log.d("MyApp", "Server encountered an error");
}
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), "UTF8"));
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
if ( result …Run Code Online (Sandbox Code Playgroud) 根据我的理解,当+运算符与两个字符串文字一起使用时,会调用concat方法来生成期望的字符串.示例 - String s = "A" + "B";
当存在null代替下面的一个文字时,它产生低于输出.我在这里很困惑 - 为什么不扔NullPointerException?
String str = null + "B";
System.out.println(str);
Run Code Online (Sandbox Code Playgroud)
输出:
nullB
主要课程:
public class ECONAPP2 {
static Scanner input= new Scanner(System.in);
static int score = 0;
static ArrayList<Integer> usedArray = new ArrayList<Integer>();
public static void main(String[] args){
app();
arrayContents();
}
public static void arrayContents() {
usedArray.add(2);
usedArray.add(1);
}
Run Code Online (Sandbox Code Playgroud)
app()方法:
public static void app() {
Random generator = new Random ();
int randomNumber = generator.nextInt(usedArray.size());
System.out.println(randomNumber);
if (randomNumber == 2) {
score();
question2();
usedArray.remove(2);
app();
}
if (randomNumber == 1) {
score();
question1();
usedArray.remove(1);
app();
}
Run Code Online (Sandbox Code Playgroud)
收到此错误:
Exception in thread "main" java.lang.IllegalArgumentException: …Run Code Online (Sandbox Code Playgroud) letme首先说,我是编程和本网站的新手.这是我第一次来这里,这是我的第二个编程项目!:)
我在编译时在底部得到一些错误,在 - x2上得到红色框并且可能也会超过y2.错误是意外类型.
基本上做一个项目来获得点的差异,这还没有完成,但我不知道如何解决编译错误.起初我尝试添加用于存储x2和y2的字段,并且确实解决了这个错误只是为了给我另一个(我删除了,因为我不想添加更多字段).最后我觉得我需要return math.sqrt(double x3) + math.sqrt(double y3)
任何建议表示赞赏,即时通讯使用蓝鸟.我相信这对你们中的一些人来说可能很容易Guru记住我的新东西!:)
public class Point {
//fields holding info for x,y
private double x;
private double y;
//default constructor, set to 0.0
public Point() {
x = 0.0;
y = 0.0;
}
//constructor that user can set field values
public Point (double x, double y) {
this.x = x;
this.y = y;
}
//This is optional. return value of x
public double getx () {
return x;
}
//This is …Run Code Online (Sandbox Code Playgroud) 我试图检查是否可以使用"isReachable"方法访问某些主机.
line 113: oaiBaseURL = "http://www.cnn.com";//////////////////////////////////////
line 114: boolean res = InetAddress.getByName(oaiBaseURL).isReachable(10000);
line 115: System.out.println("------reachable:"+res);
Run Code Online (Sandbox Code Playgroud)
并获取以下错误消息(在eclipse中):
java.net.UnknownHostException: http://www.cnn.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at com.irWizard.web.validator.WizardValidator.validateForm(WizardValidator.java:114)
Run Code Online (Sandbox Code Playgroud)
有谁知道这个错误可能是什么原因?
提前致谢!