小编use*_*796的帖子

如何在Java中创建一个新的List

我们创建一个Set:

Set myset = new HashSet()
Run Code Online (Sandbox Code Playgroud)

我们如何List在Java中创建?

java collections list

710
推荐指数
22
解决办法
183万
查看次数

如何在某一天添加​​一天?

我想在特定日期添加一天.我怎样才能做到这一点?

Date dt = new Date();
Run Code Online (Sandbox Code Playgroud)

现在我想在这个日期添加一天.

java datetime

199
推荐指数
8
解决办法
46万
查看次数

等待未来的名单

我有一个返回List期货的方法

List<Future<O>> futures = getFutures();
Run Code Online (Sandbox Code Playgroud)

现在我想要等到所有期货都成功处理完成,或者将来输出的任何任务抛出异常.即使一个任务抛出异常,也没有必要等待其他期货.

简单的方法是

wait() {

   For(Future f : futures) {
     try {
       f.get();
     } catch(Exception e) {
       //TODO catch specific exception
       // this future threw exception , means somone could not do its task
       return;
     }
   }
}
Run Code Online (Sandbox Code Playgroud)

但问题是,例如,如果第四个未来抛出异常,那么我将不必要地等待前3个期货可用.

怎么解决这个?会以任何方式倒数闩锁帮助吗?我无法使用Future,isDone因为java doc说

boolean isDone()
Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.
Run Code Online (Sandbox Code Playgroud)

java multithreading future

119
推荐指数
4
解决办法
13万
查看次数

如何在Picasso中使用磁盘缓存?

我正在使用Picasso在我的Android应用程序中显示图像:

/**
* load image.This is within a activity so this context is activity
*/
public void loadImage (){
    Picasso picasso = Picasso.with(this); 
    picasso.setDebugging(true);
    picasso.load(quiz.getImageUrl()).into(quizImage);
}
Run Code Online (Sandbox Code Playgroud)

我已启用调试,它始终显示红色和绿色.但从不显示黄色

现在,如果我下次加载相同的图像并且互联网不可用,则不会加载图像.

问题:

  1. 它没有本地磁盘缓存吗?
  2. 如何启用磁盘缓存,因为我将多次使用相同的图像.
  3. 我需要为android清单文件添加一些磁盘权限吗?

android caching image picasso

116
推荐指数
5
解决办法
10万
查看次数

为什么我在Hibernate中需要Transaction才能进行只读操作?

为什么我在Hibernate中需要Transaction才能进行只读操作?

以下事务是否锁定了数据库?

从DB获取的示例代码:

Transaction tx = HibernateUtil.getCurrentSession().beginTransaction(); // why begin transaction?
//readonly operation here

tx.commit() // why tx.commit? I don't want to write anything
Run Code Online (Sandbox Code Playgroud)

我可以用session.close() 而不是tx.commit()吗?

java database hibernate database-connection transactions

96
推荐指数
4
解决办法
7万
查看次数

如何在片段的父Activity中访问Fragment的子视图?

我有一个受支持的片段活动,它将加载diff片段.片段有一些textView,id = "score"我希望得到它的句柄,但findViewById得分的textView返回null.为什么这样?


textView放在片段中

public class MyActivity extends  extends ActionBarActivity
        implements NavigationDrawerFragment.NavigationDrawerCallbacks{

   private TextView scoreBoardTextView = null;

   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_home);
     mNavigationDrawerFragment = (NavigationDrawerFragment)
                getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
     scoreBoardTextView = (TextView) findViewById(R.id.score); //this returns null
  }

    @Override
    public void onNavigationDrawerItemSelected(int position) {
      //set fragment    
    }

}
Run Code Online (Sandbox Code Playgroud)

android android-layout

66
推荐指数
6
解决办法
8万
查看次数

匹配的通配符是严格的,但是找不到元素'context:component-scan的声明

我在尝试第一个春季项目时遇到以下错误:

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan
Run Code Online (Sandbox Code Playgroud)

这是applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

        <context:component-scan base-package="com.xyz" />

</beans>
Run Code Online (Sandbox Code Playgroud)

是什么导致错误?

java spring

64
推荐指数
4
解决办法
11万
查看次数

41
推荐指数
5
解决办法
11万
查看次数

如何检查字符串是否包含'+'字符

我想检查我的字符串是否包含+字符.我尝试了以下代码

s= "ddjdjdj+kfkfkf";

if(s.contains ("\\+"){
 String parts[] = s.split("\\+);
  s=  parts[0]; // i want to strip part after  +

}
Run Code Online (Sandbox Code Playgroud)

但它没有给出预期的结果.任何想法?

java string match

36
推荐指数
2
解决办法
21万
查看次数

如何将DateTime转换为Date

我怎样才能转换DateDateTime反之亦然?

例如

Date dt = new Date();
Run Code Online (Sandbox Code Playgroud)

现在我想转发它DateTime.

DateTime dtim = new DateTime();
Run Code Online (Sandbox Code Playgroud)

现在我想将它转换为Date.

java datetime jodatime

21
推荐指数
2
解决办法
7万
查看次数