我创建了一些将地图写入XML的代码.它似乎工作但文件打印没有新行.所以在任何XML编辑器中它只在一行上.如何为每个孩子打印到新行?
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element vdata = doc.createElement("vouchdata");
doc.appendChild(vdata);
for (Entry<String, String> entry : vouchMap.entrySet()) {
Element udata = doc.createElement("vouch");
Attr vouchee = doc.createAttribute("name");
vouchee.setValue(entry.getKey());
udata.setAttributeNode(vouchee);
Attr voucher = doc.createAttribute("vouchedBy");
voucher.setValue(entry.getValue());
udata.setAttributeNode(voucher);
vdata.appendChild(udata);
}
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("vouchdata.xml"));
// Output to console for testing
// StreamResult result = new …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置JUnit来测试我的android项目活动.
Android项目在AVD和设备上都运行正常(还有一些bug,这就是为什么我要添加一些单元测试)
我按照这些网站的步骤(它们或多或少相同,但我仍然检查所有这些只是为了确保我做的一切正确)
http://mobile.tutsplus.com/tutorials/android/android-sdk- junit-testing/
http://developer.android.com/tools/testing/testing_eclipse.html
我使用与项目相同的工作空间创建了一个测试项目,并创建了我的第一个测试用例.当我尝试运行测试时,我得到以下内容:
[2012-12-09 19:42:56 - AssassinTest] Android发布!
[2012-12-09 19:42:56 - AssassinTest] adb正常运行.
[2012-12-09 19:42:56 - AssassinTest]执行android.test.InstrumentationTestRunner JUnit启动
[2012-12-09 19:42:56 - AssassinTest]自动目标模式:首选AVD'Google_Level10'可在模拟器上使用' emulator-5554'
[2012-12-09 19:42:56 - AssassinTest]将AssassinTest.apk上传到设备'emulator-5554'
[2012-12-09 19:42:57 - AssassinTest]安装AssassinTest.apk ......
[2012-12-09 19:42:59 - 刺客测试]成功!
[2012-12-09 19:42:59 - AssassinTest]发现项目依赖,安装:刺客
[2012-12-09 19:43:01 - 刺客]已部署应用程序.无需重新安装.
[2012-12-09 19:43:01 - AssassinTest]在设备模拟器
-5554 上启动检测android.test.InstrumentationTestRunner [2012-12-09 19:43:01 - AssassinTest]收集测试信息
[2012-12-09 19 :43:04 - AssassinTest]测试运行失败:由于'java.lang.ClassNotFoundException'导致仪表运行失败
这是我从LogCat得到的:
12-09 19:43:02.929: E/dalvikvm(1255): Unable to resolve Ludes/assassi/test/InGameActivityTest; annotation class 19
12-09 19:43:02.929: D/AndroidRuntime(1255): Shutting down VM …Run Code Online (Sandbox Code Playgroud) 我有一种情况,在运行时确定接口的实现.例如,我检查一个字符串然后确定要使用哪个子类,没有IoC它看起来如下所示:
if (fruitStr == "Apple")
{
new AppleImpl().SomeMethod();
}
else
{
new BananaImpl().SomeMethod();
}
Run Code Online (Sandbox Code Playgroud)
这两个类AppleImpl和BananaImpl都实现同一个接口,比方说IFruit.
如何使用IoC/Dependency Injection来完成,特别是在Castle Windsor?
c# dependency-injection castle-windsor ioc-container inversion-of-control
有没有合法的方法来改变iOS 7中的条形按钮的大小(即文本的字体大小)?我发现默认的条形按钮大小与导航栏标题相比有点大.
当我尝试从存储过程中过滤或投影结果时,我可以在LinqPad中出现以下错误.
'LINQPad.ReturnDataSet'不包含'Where'的定义,也没有扩展方法'Where'可以找到接受"LINQPad.ReturnDataSet"类型的第一个参数
有解决方法吗?
让我们来看两个类的实例
public abstract class Shapes
{
public abstract void draw(Graphics g);
}
public class Rectangle extends Shapes
{
public void draw(Graphics g)
{
//implementation of the method
}
}
Run Code Online (Sandbox Code Playgroud)
这里的类Rectangle有扩展类,Shapes并且隐式地扩展了类Object.我知道没有其他扩展是可能的,但是我们不能调用继承类Shapes和Object多重继承吗?(因为从一个角度继承两个类是多重继承)
我正在NullPointerException调用方法并将其传递给字符串.我只能假设字符串为null.
BufferedReader之前几行从readline 初始化.这是相关的代码:
FileInputStream tmp = null;
try {
tmp = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.err.println("File not found!");
e.printStackTrace();
System.exit(1);
}
DataInputStream dis = new DataInputStream(tmp);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
create();
try {
data = br.readLine();
} catch (IOException e) {
System.err.println("First readline failed: " + e);
System.exit(1);
}
while (!data.equals(null)) {
process(data);
...
Run Code Online (Sandbox Code Playgroud)
和错误:
Exception in thread "main" java.lang.NullPointerException
at enc.read(enc.java:40)
at enc.main(enc.java:15)
Run Code Online (Sandbox Code Playgroud) 我想使用java.util.Set(和其他集合),但有一个扭曲:我想contains(),add()等等,总是调用对象equals()(这是基于身份而不是更平等的操作).我想我有办法,但它有很大的缺点.有没有正确的方法来做到这一点?对不起,如果我错过了一些明显的东西.
这就是我所做的:
public class OnlySelfEqual {
public final boolean equals(Object o){
return super.equals(o);
}
}
public class Example{
private Set<T extends OnlySelfEqual> set;
//etc
}
Run Code Online (Sandbox Code Playgroud)
我看到的主要问题(可能还有很多其他问题)是所有Ts必须从类扩展而不是实现接口,这是非常严格的.我想我想要的就像一个'反向'接口,它列出了子类型无法实现的方法(覆盖).我很确定不存在.有什么建议?
我HashMap在for循环中使用时遇到了问题.我做错了吗?我有什么改变吗?下面是代码及其输出.
码:
public static void main(String[] args) {
ArrayList<Double> arrBuckets = new ArrayList<Double>(3);
HashMap<Integer, ArrayList<Double>> hashMap = new HashMap<Integer, ArrayList<Double>>();
for(int i=1;i<5;i++)
{
arrBuckets.clear();
arrBuckets.add(0,(1.0*i)) ;
arrBuckets.add(1,(2.0*i)) ;
arrBuckets.add(2,(3.0*i)) ;
hashMap.put(i, arrBuckets);
}
System.out.println("hashMap : "+hashMap);
}
Run Code Online (Sandbox Code Playgroud)
以下是输出:
hashMap : {1=[4.0, 8.0, 12.0], 2=[4.0, 8.0, 12.0], 3=[4.0, 8.0, 12.0], 4=[4.0, 8.0, 12.0]}
Run Code Online (Sandbox Code Playgroud)
但输出应该像:
hashMap : {1=[1.0, 2.0, 3.0], 2=[2.0, 4.0, 6.0], 3=[3.0, 6.0, 9.0], 4=[4.0, 8.0, 12.0]}
Run Code Online (Sandbox Code Playgroud) 我正在尝试以正确的格式(dd/mm/yyyy)获取日期.目前它采用以下格式:MM-DD-YYYY HH24:MI:SS当我将其更改为dd/mm/yyyy时,它可以在数据库(Oracle)中运行.只要我在我的应用程序中运行它,我就会遇到异常:IndexOutOfRange at:
this.InfoList9.Add(dr["start_rcv_datetime"].ToString());
Run Code Online (Sandbox Code Playgroud)
请参阅下面的代码.
public List<String> InfoList = new List<String>();
private void populatelblDate()
{
conn.Open();
string query;
query = "select to_char(dg.start_rcv_datetime,'dd/mm/yyyy') from dc_pallet dp, dc_pallet_stock dps , dc_grv dg , sku s ,prod_size ps,colour c ,purch_order_carton_sku pocs , dc_crane_instruc dci where dps.pallet_id_no = '" + palletId.ToString() + "' and dp.pallet_id_no = dps.pallet_id_no and dg.dc_grv_id_no = dps.dc_grv_id_no and dg.order_no = dps.order_no and dg.company_id_no = dps.company_id_no and s.company_id_no = dps.company_id_no and s.company_id_no = dg.company_id_no and dps.company_id_no = c.company_id_no and dps.company_id_no = …Run Code Online (Sandbox Code Playgroud) 所以用户登录- >关闭浏览器- >再次打开浏览器- >出现错误:
HTTP Status 401 - Authentication Failed: Maximum sessions of 1 for this principal exceeded
Run Code Online (Sandbox Code Playgroud)
我需要的是捕获会话无效的事件,删除该用户的所有会话并重定向到正常登录页面
spring security配置:
<http auto-config="true" use-expressions="true">
<session-management session-fixation-protection="migrateSession">
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true"/>
</session-management>
<intercept-url pattern="/login" access="hasRole('ROLE_ANONYMOUS')" requires-channel="any"/>
<!--<custom-filter after="CONCURRENT_SESSION_FILTER" ref="sessionExpiration" /> -->
<!-- .... -->
</http>
<beans:bean id="sessionExpiration" class="com.test.security.SessionExpirationFilter">
<beans:property name="expiredUrl">
<beans:value>/login</beans:value>
</beans:property>
</beans:bean>
Run Code Online (Sandbox Code Playgroud)
我试图实现一些过滤器,但它总是显示会话为空:
public class SessionExpirationFilter implements Filter, InitializingBean {
private String expiredUrl;
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain …Run Code Online (Sandbox Code Playgroud) 请告诉我这两段代码的区别是什么:
int i = 0;
for(i; i < test; i++) {...}
Run Code Online (Sandbox Code Playgroud)
和
for(int i = 0; i < test; i++) {...}
Run Code Online (Sandbox Code Playgroud)
这些初始化i-increment变量的方法之间有什么区别吗?它会影响到什么吗?