在大多数情况下,我的HTTP请求工作没有问题.但是,他们偶尔会挂起来.
我正在使用的代码设置为如果请求成功(响应代码为200或201),则调用screen.requestSucceeded().如果请求失败,则调用screen.requestFailed().
但是,当请求挂起时,它会在调用上述方法之一之前执行此操作.我的代码有问题吗?我应该使用某种最佳做法来防止任何悬挂吗?
以下是我的代码.我将不胜感激任何帮助.谢谢!
HttpConnection connection = (HttpConnection) Connector.open(url
+ connectionParameters);
connection.setRequestMethod(method);
connection.setRequestProperty("WWW-Authenticate",
"OAuth realm=api.netflix.com");
if (method.equals("POST") && postData != null) {
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", Integer
.toString(postData.length));
OutputStream requestOutput = connection.openOutputStream();
requestOutput.write(postData);
requestOutput.close();
}
int responseCode = connection.getResponseCode();
System.out.println("RESPONSE CODE: " + responseCode);
if (connection instanceof HttpsConnection) {
HttpsConnection secureConnection = (HttpsConnection) connection;
String issuer = secureConnection.getSecurityInfo()
.getServerCertificate().getIssuer();
UiApplication.getUiApplication().invokeLater(
new DialogRunner(
"Secure Connection! Certificate issued by: "
+ issuer));
}
if (responseCode != 200 && responseCode != 201) {
screen.requestFailed("Unexpected …Run Code Online (Sandbox Code Playgroud) 我想创建一个正常的AlertDialog.我使用了android dev docs提供的示例.我刚刚将DIALOG_PAUSED_ID更改为DIALOG_DELETEDB.如果我执行我的代码并按下按钮,而该按钮应该创建对话框,我会得到以下错误日志:
04-29 01:01:20.973: WARN/dalvikvm(1168): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-29 01:01:20.973: ERROR/AndroidRuntime(1168): Uncaught handler: thread main exiting due to uncaught exception
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 4
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): at android.app.Activity.createDialog(Activity.java:871)
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): at android.app.Activity.showDialog(Activity.java:2483)
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): at mjb.project.AVV.Favs.onMenuItemSelected(Favs.java:111)
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:525)
04-29 01:01:20.993: ERROR/AndroidRuntime(1168): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
04-29 01:01:20.993: …Run Code Online (Sandbox Code Playgroud) 如何处理私有方法的单元测试?
我有一个类将Employee数据加载到数据库中.这是一个示例:
>
public class EmployeeFacade
{
public Employees EmployeeRepository = new Employees();
public TaxDatas TaxRepository = new TaxDatas();
public Accounts AccountRepository = new Accounts();
//and so on for about 20 more repositories etc.
public bool LoadAllEmployeeData(Employee employee)
{
if (employee == null)
throw new Exception("...");
bool exists = EmployeeRepository.FetchExisting(emps.Id);
if (!exists)
{
EmployeeRepository.AddNew();
}
try
{
EmployeeRepository.Id = employee.Id;
EmployeeRepository.Name = employee.EmployeeDetails.PersonalDetails.Active.Names.FirstName;
EmployeeRepository.SomeOtherAttribute;
}
catch() {}
try
{
emps.Save();
}
catch(){}
try
{
LoadorUpdateTaxData(employee.TaxData);
}
catch() {}
try
{ …Run Code Online (Sandbox Code Playgroud) 如何处理您在开发过程中不了解语言/框架的事实?
例如,假设一组Java开发人员即将启动.NET项目,他们不太了解该平台,最终可能会找到框架已经解决或解决的更好的解决方案.
我遇到的问题是:在这种情况下哪些是最好的做法?在进行良好的实践之前是RTFM吗?什么时候应该停止RTFM并开始询问/搜索/播放?不是RTFM而只是搜索/询问/播放一个好习惯吗?估计怎么样?
我想听听你的经历:-)
我正在研究Scala 2.8集合类的源代码.我对层次结构有疑问scala.collection.Traversable.请查看以下声明:
package scala.collection
trait Traversable[+A]
extends TraversableLike[A, Traversable[A]]
with GenericTraversableTemplate[A, Traversable]
trait TraversableLike[+A, +Repr]
extends HasNewBuilder[A, Repr]
with TraversableOnce[A]
package scala.collection.generic
trait HasNewBuilder[+A, +Repr]
trait GenericTraversableTemplate[+A, +CC[X] <: Traversable[X]]
extends HasNewBuilder[A, CC[A] @uncheckedVariance]
Run Code Online (Sandbox Code Playgroud)
问题:为什么要使用类型参数进行Traversable扩展- 为什么不呢?我试着尝试一个具有相同结构的小程序,并在我尝试将其更改为时收到一条奇怪的错误消息:GenericTraversableTemplate[A, Traversable][A, Traversable[A]]Traversable[A]
error: Traversable[A] takes no type parameters, expected: one
Run Code Online (Sandbox Code Playgroud)
我猜这个@uncheckedVariance注释的使用GenericTraversableTemplate也与此有关吗?(这似乎是一种可能不安全的黑客,迫使事情发挥作用......).
编辑 - 在这个问题中找到关于注释的一些有用的答案(因为GenericTraversableTemplate它用于具有不同方差的可变和不可变集合).
问题:当您查看层次结构时,您会看到Traversable继承HasNewBuilder两次(一次通过TraversableLike和一次通过GenericTraversableTemplate),但类型参数略有不同.这是如何工作的?为什么不同的类型参数不会导致错误?
要使用screenplay包进入一些对话,我必须使用
\begin{dialogue}{Johnny} Some dialogue. \end{dialogue}
\begin{dialogue}{Jane} I see. \end{dialogue}
Run Code Online (Sandbox Code Playgroud)
一段时间后,它会变得有点乏味.是否可以指定自定义命令,以便我可以使用类似的东西
\dialogue{Johnny} Some dialogue.
\dialogue{Jane} I see.
Run Code Online (Sandbox Code Playgroud)
代替?
作为更大的应用程序的一部分,我试图将IP地址转换为二进制.目的是稍后计算LAN唤醒流量的广播地址.我假设有一种更有效的方式来做我想的方式.这是通过八位字节分解IP地址,在必要时将0添加到每个八位字节的开头,将每个八位字节转换为二进制,然后组合结果.我应该看看netaddr,套接字还是完全不同的东西?
示例:从192.168.1.1到11000000.10101000.00000001.00000001
我试图迭代一个JSON对象来导入数据,即标题和链接.我似乎无法获得过去的内容:.
JSON:
[
{
"title": "Baby (Feat. Ludacris) - Justin Bieber",
"description": "Baby (Feat. Ludacris) by Justin Bieber on Grooveshark",
"link": "http://listen.grooveshark.com/s/Baby+Feat+Ludacris+/2Bqvdq",
"pubDate": "Wed, 28 Apr 2010 02:37:53 -0400",
"pubTime": 1272436673,
"TinyLink": "http://tinysong.com/d3wI",
"SongID": "24447862",
"SongName": "Baby (Feat. Ludacris)",
"ArtistID": "1118876",
"ArtistName": "Justin Bieber",
"AlbumID": "4104002",
"AlbumName": "My World (Part II);\nhttp://tinysong.com/gQsw",
"LongLink": "11578982",
"GroovesharkLink": "11578982",
"Link": "http://tinysong.com/d3wI"
},
{
"title": "Feel Good Inc - Gorillaz",
"description": "Feel Good Inc by Gorillaz on Grooveshark",
"link": "http://listen.grooveshark.com/s/Feel+Good+Inc/1UksmI",
"pubDate": "Wed, 28 …Run Code Online (Sandbox Code Playgroud) 我正在尝试做类似的事情:
#include <iostream>
#include <vector>
#include <ctime>
class Clickomania
{
public:
Clickomania();
std::vector<std::vector<int> > board;
};
Clickomania::Clickomania()
: board(12, std::vector<int>(8,0)) <<<<<<<
{
srand((unsigned)time(0));
for(int i = 0; i < 12; i++)
{
for(int j = 0; j < 8; j++)
{
int color = (rand() % 6) + 1;
board[i][j] = color;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,显然我不能用这种方式初始化矢量的"板"矢量.
如何创建二维矢量类型的公共成员并正确初始化它?
我正在使用Cucumber + capybara + selenium来运行自动化测试,但我找不到断言显示javascript警报的方法.
这个问题似乎有一个硒的解决方案,但我无法弄清楚如何使用Capybara调用selenium对象.
有没有一种简单的方法来测试使用Capybara的警报?或者有解决方法吗?